<?php
class Mytpl{
 //输出页面
 protected $tpl_val = array();
 function display($url){
  $content = file_get_contents($url); //获取模板资源
  foreach ($this->tpl_val as $k => $v) {//翻译
   $content = str_repeat('{$'.$k.'}', $v,$content);
  $complie_url = "文件夹名/".md5($url).".php";//设置临时文件路径    md5()加密
  file_put_contents($complie_url, $content);//输出资源
  include_once $complie_url;
 }
 function assign($k,$v){//将许可的变量放入数组
   $this->tpl_val[$k] = $v;
 }
}
$tpl = new Mytpl();
$tpl->assign('a','哈哈');
$tpl->display('index2.html');

 

 

 

 

----------------------------------index2.html------------------------------

<!DOCTYPE HTML>
<html >
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 </head>
 <body>
 你好{$a}
 </body>
</html>

posted on 2018-05-21 11:40  PHP`reader  阅读(91)  评论(0编辑  收藏  举报