How to parse PHP syntax in a .html file on server?

后端 未结 4 615
一向
一向 2021-01-22 07:29

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).

相关标签:
4条回答
  • 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
    
    0 讨论(0)
  • 2021-01-22 07:45

    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.

    0 讨论(0)
  • 2021-01-22 07:45

    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.

    0 讨论(0)
  • 2021-01-22 07:59

    ModRewrite

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

    AddType

    AddType application/x-httpd-php .htm .html
    
    0 讨论(0)
提交回复
热议问题