【发布时间】:2010-10-03 09:45:38
【问题描述】:
我认为 PHP 模板系统的基本原理是字符串替换,对吧? 那么我可以只使用一个字符串来保存我的 html 模板代码,比如
$str_template = "<html><head><title>{the_title}</title><body>{the_content}</body></html>"
在下面的代码中,只需执行 str_replace 即可将数据推送到我的模板变量中,例如
str_replace( $str_template, '{the_title}', $some_runtime_generated_title );
str_replace( $str_template, '{the_content}', $some_runtime_generated_content );
最后
echo $str_template;
这是否有望使整个变量传递过程更快一些?我知道这可能是一个奇怪的问题,但有人试过吗?
【问题讨论】: