<?php class mini { //模板文件目录 public $template_dir = ''; //模板编译后的文件目录 public $compile_dir = ''; //定义数组接收外部变量 public $tpl_var = array(); public function assign($key,$value){ $this->tpl_var[$key] = $value; //var_dump($this->tpl_var); //die; } public function display($template){ $comp = $this->compile($template); include $comp; } //编译 public function compile($template){ //读取内容 $source = file_get_contents($this->template_dir.'/'.$template); //替换标签 $source = str_replace('{$', '<?php echo $this->tpl_var[\'', $source); $source = str_replace('}', '\'];?>', $source); //echo $source; $comp = $this->compile_dir.$template.'.php' ;// //var_dump($comp); //存放内容 file_put_contents($comp,$source);//将内容放入文件 return $comp; } }