qns_fengyusong 发表于 2017-3-4 12:36:01

php模板简单原理

<?php
class tplEngine{
protected $tpl_vars = array();//设置成属性便于全局赋值
public function assign($key,$val){
   $this->tpl_vars[$key] = $val;
}
public function display($tpl){


if(!file_exists($tpl.".php")){

$html = file_get_contents($tpl);

$html = preg_replace('/\{\$(\w+)\}/','<?php echo      $this->tpl_vars["\\1"]; ?>',$html);

file_put_contents($tpl.".php",$html);
}

include $tpl.".php";
}





}
页: [1]
查看完整版本: php模板简单原理