Parsing PHP in .html Files

Parsing PHP in web pages that end in .html or .htm, possible? Absolutely!

You're suddenly hosted on the Apache web server and perhaps you've just moved to a host that supports PHP and you want to try your hand at inserting cool PHP codes into them,

...you're probably thinking, Oh man, now I have to rename all my web pages to newpage.php!. Think again...

You may leave your web pages as index.htm or whatever.html and just start inserting your PHP codes inside it and have it parsed just as if they were placed in an index.php or whatever.php file!

Edit the .htaccess file

How? Well, here's what you should do:

Go to your WWW root, usually it looks like this -
path: /home/username/public_html

Look for the file named .htaccess. If it's not there, create a blank page using NotePad or Dreamweaver and save it as .htaccess

Now edit this file by adding the following lines:

code:
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html

Save and close the .htaccess file. Upload it to your webserver (to your WWW root) and that's it!

Sample PHP code in a .html webpage

Now create a test file and filename it test.html

Copy the following html into it:

php:


<html>
<head></head>
<body>
  <h1>
  <?php echo "I LOVE PHP!"; ?>
  </h1>
</body>
</html>

Upload it to your web server and view it using your browser. You will see that it works just fine.

TOP

Do you like the new design?

 Yes

 No

 Don't know