A problem with a php template

93 3

I wrote a template class to filter the content label in the html file into a normal php tag, and then output.

File get contents that are currently read. Html, and then regular filtering is normal, the last output to the page becomes a pure string, similar to the.

<?php
include(Template::getfile('header'));
?>
这里是html...

How do I make it run.

Ps: the way I used to do this is to save the strings of these output as a. Php file, and then include this file. Now that the loop is changed, the directory io isn't supported, so I'm going to execute it directly, whether it's feasible?

1 Answers

56 3

A string can be executed with eval, and the following my_template_parser is your own template function. But note that eval 's execution efficiency is low and may have memory problems, so it's recommended that you use it locally for testing, formal use, or.

eval(my_template_parser(file_get_contents('my-template.html')));
...