Ian
Ian

Reputation: 391

Call the php function inside the html tag

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?

Upvotes: 0

Views: 1637

Answers (3)

jh314
jh314

Reputation: 27802

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.

Upvotes: 1

Orangepill
Orangepill

Reputation: 24655

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.

Upvotes: 3

cricket4lyfe921
cricket4lyfe921

Reputation: 51

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.

Upvotes: 0

Related Questions