How To Enable and Embed PHP Script Code Into an HTML Page

Computer Tips, Web Development | 6 comments

Using PHP code script on HTML pagesNormally, 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.

You May Also Like


  1. Paul Chavaux

    this causes the php page to attempt to download instead of display.

  2. After5PC

    Another option is to use a rewrite rule via htaccess to have the .html file read as a .php

  3. Jez Lister

    I assume that the PHP is still processed on the server?

  4. mega6382

    I cant understand about htaccess in what should i rename it (.htaccess) or (htaccess.htaccess)

  5. After5PC

    The full file name, when everything is done will be: .htaccess

  6. Kudzai

    Thanks a million for this tutorial. Im building a massive eCommerce site using PHP and MySQL where the requirement was that each product item page should be a static html fite. This posed a major development challenge because i needed to run dynamic php code on all pages – to retrieve and display a snapshot of the ShoppingCart Session (Total Balance, Number of Items added) So you can imagine the challenge there. After 7 years of PHP programming I didn’t realise I could infact embed PHP code in a .html file. If you had a donate button I would have donated something.

    Again, Thank You

Submit a Comment

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


Powerful SMS Mass Texting System For Your Organization

Use my incredible AFTER5PC SMS system to TRANSFORM your existing Android phone into a POWERFUL mass texting and marketing communication tool! My SMS gateway is perfect for churches, small businesses, and other organizations of all sizes.

Ecommerce + Chatbot + Email + SMS + Social Media Automation

Use this amazing platform to get all the tools that you need in order for your business to succeed online! This powerful all-in-one system is the most cost-effective way to connect to your existing customers or to obtain fresh leads and get more sales!


Limited-Time Special Offer For New Web Design Clients  


Enjoy $1,000 worth of coupons from your choice of favorite restaurants and fast good chains, plus grocery coupons of your choice! These are restaurants such as TGIF Fridays, Chili’s, Olive Garden, Red Lobster, Applebee’s, Sizzler, I-Hop, Denny’s just to list a few. Also includes fast food chains such as McDonald's, Hardee's, Quizno's, Taco Bell, Dairy Queen, Burger King, Carl's Jr., Jack-In-The-Box and many more. Plus, enjoy grocery coupons from a list of national brand name products that will definitely save your family money. Total savings of $1,000! This offer is valid for USA residents only.