时时商务社区

标题: Pain 全世界最小最简单的PHP模板引擎 (普通版) [打印本页]

作者: yj1281    时间: 2018-2-14 08:32

            打包下载
Pain.php
[U]复制代码[/U] 代码如下:
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("{@", "", $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
[U]复制代码[/U] 代码如下:
assign("songyu",$songyu);
$pain->assign("zhangyuan",$zhangyuan);
$pain->display("new_file.html");
?>

new_file.html
[U]复制代码[/U] 代码如下:




new_file


{@$songyu@}

{@$zhangyuan@}


            
            
您可能感兴趣的文章:
  • 需要使用php模板的朋友必看的很多个顶级PHP模板引擎比较分析
  • PHP中MVC模式的模板引擎开发经验分享
  • PHP原生模板引擎 最简单的模板引擎
  • CodeIgniter使用phpcms模板引擎
  • php smarty模板引擎的6个小技巧
  • php模板引擎技术简单实现
  • 自定义min版smarty模板引擎MinSmarty.class.php文件及用法
  • 简单的自定义php模板引擎
  • PHP的自定义模板引擎
  • PHP实现简单的模板引擎功能示例
            




    欢迎光临 时时商务社区 (http://bbs.4435.cn/) Powered by Discuz! X3.2