开发自己的模板引擎
MyTpl.class.php
<?phpclassMyTpl{private$tpl_vars=array();//分配publicfunctionassign($key,$value){$this->tpl_vars[$key]=$value;}publicfunctiondisplay($tpl){$contents=file_get_contents($tpl);foreach($this->tpl_varsas$k=>$v){//替换将{$name}替换成真实的数据$contents=str_replace('{$'."$k".'}',"$v",$contents);$compile='./templates_c/'.md5('show.html').'.php';file_put_contents($compile,$contents);require$compile;}}}$tpl=newMyTpl;$tpl->assign('name','张四');$tpl->display('./template/show.html');自定义视图
template/show.html
<!DOCTYPEhtml><html><head><metacharset="UTF-8"><title>Inserttitlehere</title></head><body>{$name}</body></html>
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。