模板引擎 - 一个php模板的问题

WBOY
Release: 2016-06-06 20:52:26
Original
887 people have browsed it

我写了一个模板类用来将 .html文件中的内容标签过滤成正常的php标签,然后输出。

目前读取.html用的file_get_contents,然后正则过滤都很正常,最后输出到页面里变成了纯字符串,类似

 这里是html...
Copy after login
Copy after login

请问我要如何让它执行?

PS:过去我用的方法是将这些输出的字符串保存为一个.php的文件,然后include这个文件。现在环境变了,不支持目录IO,所以我想直接执行它,是否可行?

回复内容:

我写了一个模板类用来将 .html文件中的内容标签过滤成正常的php标签,然后输出。

目前读取.html用的file_get_contents,然后正则过滤都很正常,最后输出到页面里变成了纯字符串,类似

 这里是html...
Copy after login
Copy after login

请问我要如何让它执行?

PS:过去我用的方法是将这些输出的字符串保存为一个.php的文件,然后include这个文件。现在环境变了,不支持目录IO,所以我想直接执行它,是否可行?

可以用eval来执行字符串,下面的my_template_parser是你自己的模板函数。但是注意eval的执行效率很低而且可能会有内存问题,所以只建议本地用来测试,正式使用还是替换成php文件再include的好。

eval(my_template_parser(file_get_contents('my-template.html')));
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!