0

I had write a simple html code and save it as testing.html in eclipse. Below are the code:

<html>
<body>
<?php
function helo()
{
     echo "hello";
}
echo "say ";
helo();
?>
</body>
</html> 

When I run via apache Tomcat, it did not show any things in my browser. I had tried to write a simple html code (without php code inside the html code) and it can run via apache Tomcat. May I know why this happen? Is it something wrong with my code? Or some thing go wrong when I set up in eclipse?

Ian
  • 391
  • 1
  • 17
  • 5
    PHP generally isn't parsed in html documents... try changing the file to testing.php and see what you get. – Orangepill Jul 15 '13 at 02:43
  • 1
    I don't like the situation when someone posts a correct answer in the comment and after 5/10 minutes someone else just copy that and write in their own language as an answer. @Orangepill: you should post your comment as an answer. voting it up here isn't enough :) – Fallen Jul 15 '13 at 02:52
  • 1
    @Fallen - It seems appropriate as a comment since there is a slew of possibilities that could be causing this problem. However, once confirmed, it should be posted as an answer and accepted by the OP. Then, and only then, it is appropriate as an answer (IMO). – nickb Jul 15 '13 at 03:04
  • 1
    For example, here is my "guess" on why it's not working: Tomcat is a Java server engine and the OP would need to be using a Java <=> PHP bridge in order to parse PHP files. OP should be using Apache HTTP server, properly configured with PHP, to execute a PHP file. – nickb Jul 15 '13 at 03:06
  • @nickb: +1 and agreed. But the conclusion of my comment was based on the first part of my comment :) Thanks! – Fallen Jul 15 '13 at 03:11

3 Answers3

3

PHP generally isn't parsed in html documents... try changing the file to testing.php and see what you get.

If that still doesn't work then it's possible php isn't installed or correctly configured on your hosting environment.

Orangepill
  • 24,500
  • 3
  • 42
  • 63
  • Probably not - Tomcat is a Java server engine. – nickb Jul 15 '13 at 03:24
  • but it is possible to run [php on a java servlet](http://stackoverflow.com/questions/779246/run-a-php-app-using-tomcat) – Orangepill Jul 15 '13 at 03:29
  • @Orangepill but I cannot download PHP 5 at http://my1.php.net/get/php-5.2.9-2-Win32.zip/from/a/mirror ...still got any link for me to download the PHP 5? – Ian Jul 15 '13 at 08:46
  • @Orangepill - The top answer is referring to delegating PHP to Apache, and letting Tomcat handle the servlets. Besides, it's much more involved than renaming the HTML file to PHP, which is why I highly doubt this will solve the OP's problem. – nickb Jul 15 '13 at 12:50
  • @nickb Yes. I already renaming my HTML file to PHP, but it still cannot solve my problem. – Ian Jul 17 '13 at 01:08
1

Your web server doesn't run the PHP preprocessor on your html document.

To fix this, you need to rename your testing.html file to testing.php.

jh314
  • 27,144
  • 16
  • 62
  • 82
0

Your server reads the ".html" extension and interprets the file as an html file. Therefore, you cannot interweave php in it. However, if you change the filename to testing.php, the tomcat server will interpret the php, and you will get your desired result.

  • Probably not - Tomcat is a Java server engine. – nickb Jul 15 '13 at 03:23
  • Hi, @cricket4lyfe921 I already renaming my HTML file to PHP, but it still cannot solve my problem. Do u know why this happen? – Ian Jul 23 '13 at 01:09