跳转到主内容
新派编程网 - 新潮编程理念,全新技术课堂!

Pain 全世界最小最简单的PHP模板引擎 (普通版)_php模板_脚本之家

PHP全世界最小最简单的模板引擎------Pain (普通版),不同于smarty,所有的变量以{@ @}括起来,有助于大家对模板引擎的了解。

Pain.php代码如下:php
var[$variable]=$value;}public function display($template_name,$return_string=false){//first find whether the tmp file in tmp dir exists.

if(file_exists("tmp/temp_file.php")){unlink("tmp/temp_file.php");}extract($this->var);$tpl_content=file_get_contents($template_name);$tpl_content=str_replace("{@", "php echo ", $tpl_content); ", $tpl_content);//create a file in the /tmp dir and put the $tpl_contentn into it, then//use 'include' method to load it!$tmp_file_name="temp_file.php";//$tmp is the handler$tmp=fopen("tmp/".$tmp_file_name, "w");fwrite($tmp, $tpl_content);include "tmp/".$tmp_file_name;}}?>test.php代码如下:php
assign("songyu",$songyu);$pain->assign("zhangyuan",$zhangyuan);$pain->display("new_file.html");?>new_file.html代码如下:BR>"http://www.w3.org/TR/html4/strict.dtd">new_file{@$songyu@}{@$zhangyuan@}

相关文章