<?php
class Smarty{
public $template_dir;//模板目录
public $compile_dir;//编译目录
public $arr=array();//定义一个数组,用以存放assign中的第二个参数传过来的值
public function __construct($template_dir="../templates",$compile_dir="../templates_c"){
$this->template_dir=$template_dir;
$this->compile_dir=$compile_dir;
}
public function assign($content,$replacment=null){
if($content!=""){ //如果指定模板变量,才将要赋的值存储到数组中
$this->arr[$content]=$replacment;
}
}
public function display($page){
$tplFile=$this->template_dir."/".$page;
if(!file_exists($tplFile)){
return;
}
$comFile=$this->compile_dir."/"."com_".$page.".php";
$tplContent=$this->con_replace(file_get_contents($tplFile));
file_put_contents($comFile,$tplContent);
include $comFile;
}
public function con_replace($content){
$pattern=array(
'/<{\s*\$([a-zA-Z_][a-zA-Z_0-9]*)\s*}>/i'
);
$replacement=array(
'<?php echo $this->arr["${1}"] ?>'
);
return preg_replace($pattern,$replacement,$content);
}
}
?>
深入浅出之Smarty模板引擎工作机制
3星 · 超过75%的资源 需积分: 9 165 浏览量
2011-12-10
22:15:34
上传
评论
收藏 2KB RAR 举报
曾是土木人
- 粉丝: 67
- 资源: 29
最新资源
- libjpeg 编译所需的 Win32.mak vs编译libjpeg
- 自动驾驶-状态估计和定位-粒子滤波实现和源码.pdf
- 数据可视化-智慧物流服务中心大屏页面.zip
- yolov5,SSD 可能使用到的一些代码
- bbbbbbbbbbbbbbbbbb
- 安卓逆向学习笔记之Frida Stalker 还原OLLVM AES.docx
- 安卓逆向学习笔记之unicorn来trace还原OLLVM Base64.docx
- 基于jquery的自定义表格组件实现
- Nessus最新20240426离线安装插件all-2.0.tar.gz
- 最新版本私钥助记词碰撞器大富豪使用python进行制作通过接口的方式进行验证支持多币种多链多网络一分钟万次验证高出货率
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈