Skip to content Skip to sidebar Skip to footer

How To Parse Php Syntax In A .html File On Server?

This feels like an extremely n00b question, but here goes... I have a series of HTML files with a small amount of HTML content inside each (exported from a live system). Its not fe

Solution 1:

Well I'm rather sure you're not very accustomed to the way the apache engines works with php. In truth, this isn't a php question but an apache one (in case you're using apache, which I will assume)

The simplest way of doing this, is to add a .htaccess with the following contents:

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

This basically tells apache that all .html files should be parsed by PHP, read more about it here.

What you actually saw, I suspect are URL rewrites, read more about mod_rewrite.

Solution 2:

If you can't modify the server's setup, then you're SOL. You have to tell the server that .html files should be treated as PHP scripts. There's no way around this. It won't magically start sending them through the PHP parser unless you tell it to.

On an Apache setup, it's a matter of putting in a configuration directly, such as

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

Solution 3:

ModRewrite

RewriteEngine on
RewriteRule ^(.*).html$ $1.php

AddType

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

Solution 4:

I worked around the problem by adding a config variable which is then used in a string replacement call to replace an export-generated string with one which someone can update in a config file, before burning to CD. I can get away with this because the string replacement is essentially the only PHP in these HTML files. I'll close this question after... leaving for anyone to check up on/read about quickly.

Post a Comment for "How To Parse Php Syntax In A .html File On Server?"