如何在服务器上的.html文件中解析PHP语法? [英] How to parse PHP syntax in a .html file on server?

查看:215
本文介绍了如何在服务器上的.html文件中解析PHP语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一系列HTML文件,每个HTML文件内都有一小段HTML内容(已导出来自现场系统)。对于更改文件扩展名是不可行的,因为当我交出项目时,我不会执行这个'导出 - 刻录到CD'的过程。



这里是一个示例页面,它非常基本,它是 01.html

 <!DOCTYPE HTML PUBLIC -  // W3C // DTD HTML 4.01 Transitional // ENhttp://www.w3.org/TR/html4/loose.dtd\"> 
< html>
< head>
< meta http-equiv =content-typecontent =text / html; charset = utf-8/>
< link rel =stylesheettype =text / csshref =../ css / styles.css/>
< title>介绍< / title>
< / head>
< body>
< h1 class =chaptertitle>简介< / h1>
< div>除了正常的现金工资之外,FBT是向员工提供的非现金福利。管理员用户的附加福利的主要类别是:< / p>
< ul>
私人使用或私人使用的雇主汽车的可用性;< / li>
< / ul>
< / div>
< / body>
< / html>

文件链接到主页面,在这方面一切正常 - 但我确定我已经看到带有.html扩展名的页面解析PHP语法,我该如何启用/执行此操作?目前,我认为我可以在上面的例子中对'Administrator User'进行搜索/替换,例如:

 <?php echo $ CFG-> username; ?> 

...其中该变量已定义且可用 - 但该页面正在被解析为HTML。在某些方面,这并不意外,在某些方面,就像我说的,我确信我已经看到PHP代码在扩展名为.html的文件中解析。



它运行在Server2Go堆栈上(用于刻录到CD),但在测试期间它正在WAMP堆栈上运行。我无法修改很多关于Server2Go的信息。






Ack!对不起,澄清:
$ b

< body> 标记内的每一个字都被拉出并用于PHP上下文中,一个名为' generate_book.php '的页面,它显示被拉出的内容为PHP页面自己的< body> 标记。



对不起,这有点重要:P

解决方案

我通过添加一个配置变量来解决这个问题,该配置变量随后用于字符串替换调用中,以便在刻录到CD之前用导出生成的字符串替换某个人可以在配置文件中更新的字符串。我可以逃避这一点,因为字符串替换实质上是这些HTML文件中唯一的PHP。我会在...之后关闭这个问题,让任何人快速检查/阅读。

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 feasible to change file extensions, as I will not be the person performing this 'export - burn to CD' process when I hand my project over.

Here's a sample page, its extremely basic, it is "01.html":

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../css/styles.css" />
<title>Introduction</title>
</head>
<body>
<h1 class="chaptertitle">Introduction</h1>
<div>
    <p>FBT is imposed on non-cash benefits provided to employees in addition to their normal cash salary. The main categories of fringe benefit for Administrator User are:</p>
    <ul>
        <li>The private use, or availability for private use, of an employer’s motor vehicles;</li>
    </ul>
</div>
</body>
</html>

The files are linked to from a main page, everything works fine in that regard - but I am sure I've seen pages with a .html extension parse PHP syntax, how can I enable/ do this? Currently, I'd thought I could do a search/replace on things like 'Administrator User' in the above example to something like:

<?php echo $CFG->username; ?>

...where that variable is defined and available - but the page is being parsed as HTML. In some ways this isn't a surprise, in some ways it is, as like I say I'm sure I've seen PHP code parsed in a file with a .html extension.

It is running on a Server2Go stack (for burning to CD), but during testing it is running on a WAMP stack. I'm not able to modify much about Server2Go.


Ack! Sorry, to clarify:

everythign inside the <body> tag is pulled out and used in a PHP context, a page named 'generate_book.php' which displays the pulled out contents as the PHP pages' own <body> tag.

Sorry, that was somewhat important :P

解决方案

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.

这篇关于如何在服务器上的.html文件中解析PHP语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆