Using PHP Script in HTML File?
I have a very simple HTML file containing PHP scripts. Even though
I enabled PHP, PHP scripts doesn’t seem executing when
embedded in HTML files with .htm or .html extensions.
It only displays ‘Toto’ and not ‘Tada’ with the .html file
shown below.
It worked fine when I renamed the file with .php extension.
All my menu’s built using .html file extension as I’m using
Yahoo! Site Builder. Is there any way I can get PHP scripts
working embedded in .html file?
—–
<html>
<body>
<h1>Toto</h1>
<?php
echo "<h1>Tada</h1>"
?>
</body>
</html>
—–
September 2, 2010 | Filed Under Scripts FAQs
Comments
4 Responses to “Using PHP Script in HTML File?”
Powered by Yahoo! Answers
What you are observing is in fact the intended behavior. There are ways to change that behavior (specifics depend on how your PHP is configured), but you have to have administrator rights on your server. On shared hosting services, you usually don’t.
Consider moving away from Yahoo! Site Builder. It is a very nice tool for a beginner, but you seem to have outgrown it…
It would need to have .php extension.
Just rename it back to php and html will work fine then
For apache to know that it has to execute a particular file(.html or .htm in your case) using php and not just consider it as a static file, u have to tell it the same, by using the following lines in your httpd.conf file :
AddType application/x-httpd-php .html .htm .php
But this has one side effect, that every single htm/html of yours will be parsed by the php engine.
I agree with tutejasaurabh, but as he said this solution makes the server to parse all the html files which is an extra load for the server. So, consider modifying your navigation links. You can do that with Yahoo! SiteBuilder.
All The Best.