How to parse PHP in html pages

How to parse PHP in web pages having extension as .html / .htm?

This can be done using .htaccess file in the directory where you want all your .html files to be treated as php while still showing .html in the address bar.

Create a simple text file. Put the following code in that file.

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

Save it and name it as “.htaccess” (on windows you might get problems in saving since it starts with a dot, in that case save it with any name, upload to server and then rename it) .

Upload it to your web server to your WWW root or the directory where you want this functionality.

Now lets try if it works or not.

Create a test html file, name it something lie test.html

Yes, extension should be .html

Put some php code in the html (something like below)

<html><body>
<?php echo "Success, this is from PHP code inside HTML";  ?>
</body></html>

Upload this html file (test.html) also to your web server (under the directory where you placed .htaccess ).

Open this file in any browser.

If you get the message “Success, this is from PHP code inside HTML”, time to cheer.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>