All Collections
PHP Advanced
How to Parse PHP in HTML Files
How to Parse PHP in HTML Files

Parsing PHP in HTML files

Updated over a week ago

PHP is a powerful scripting language used for creating dynamic web applications. Typically, PHP files have a .php extension, allowing the server to recognize and process them accordingly. However, there are situations where you might want to embed PHP code directly within an HTML file, such as for integrating dynamic content or executing specific functions within the HTML structure.

To parse PHP code in HTML files, inform the server that the .html and .htm files contain PHP code by following these steps:

Step 1 - Preparations

Create a backup of your .htaccess file before proceeding. An easy way of doing it is by copying the file and renaming it, for example, to .htacces-backup using the File Manager.

If the file is not present in the public_html folder of your website, create it.

Step 2 - Edit the .htaccess File

Next, open the .htaccess file using the File Editor and add the following directive to the .htaccess file:

AddHandler application/x-httpd-lsphp .htm .html

After saving this change, you can now embed PHP code directly within your HTML markup.

Did this answer your question?