Normally, a PHP code can only be inserted on a PHP file. If your website is in HTML, then you have to convert all your “.html files” into “.php” in order to be able to embed PHP codes. If you have 1-page or 3-page website, that is not such a hassle to do. However, when you have a large html-based website, that becomes a big problem and a major headache!
Well, here’s an alternative solution that you might like! You no longer need to convert your html site into PHP — thus, eliminating the hassle. You can now use your regular html site as it is and make it behave as if it was a PHP-based website so that you can embed PHP codes on your pages. For example, you can finally add RSS feeds on your html page so that you can have new and fresh content everyday on your website.
How is this possible? This method only works if your server supports .htaccess. If you are unsure if htaccess is supported on your server, contact your web hosting provider.
(1) First, open notepad and create a new text file.
(2) Enter the following on the document:
RemoveHandler .html .htm
AddType application/x-httpd-php .php .html .htm
(3) Save the file as “htaccess.txt” (txt is the default extension of a file made by Notepad program on your PC).
(4) Upload this file unto your server.
(5) Rename the file as “.htaccess”
(6) Insert the PHP code into the html page that you want it on
(7) Enjoy better features on your site!
Hope this information helped you.
If you need any other type of assistance with your online projects, contact me with your requirements. If it’s within my scope, I’ll respond with a price quote accordingly.
→ Posted in Category: Computer Tips, Web Development
Here's where you can leave a comment regarding the above post.
2 Responses to “How To Enable and Embed PHP Script Code Into an HTML Page”
Leave a Reply



























this causes the php page to attempt to download instead of display.
Another option is to use a rewrite rule via htaccess to have the .html file read as a .php