Saturday, April 17, 2010

how to include PHP code in html files

As a scripting language, PHP offers the flexibility to be intermixed with HTML code, to enhance the functionality of web pages. To do this, you need to instruct the web server to pass the HTML pages trough the PHP interpreter, so that any snippets of code could get executed.

If you use Apache, one easy way to accomplish this is to use the .htaccess file in the folder of your app and add some clauses like this:

AddType application/x-httpd-php .html 
Addhandler x-httpd-php .html

You can place the .htaccess file in the parent folder that's closest to the html files containing PHP. Doing so will avoid any overhead in parsing files that wouldn't contain PHP code.

No comments: