php模版解析类.zip

时间:2022-07-31 04:11:05
【文件属性】:
文件名称:php模版解析类.zip
文件大小:2KB
文件格式:ZIP
更新时间:2022-07-31 04:11:05
类库下载-php模版解析类 <?php class Parser {   private $_tpl;   public function __construct($_tplFile)   {     if (! $this->_tpl = file_get_contents($_tplFile)) {       exit('ERROR:模版文件读取错误');     }   }   private function parvar()   {     $_patten = '/<!--\s \{\$([\w] )\}\s -->/';     if (preg_match($_patten,$this->_tpl)) {       $this->_tpl = preg_replace($_patten, "<?php echo \$this->_vars['$1'];?>",$this->_tpl);     }   }   private function parif(){     $_pattenif = '/<!--\s \{if\s \$([\w] )\}\s -->/';     $_pattenElse = '/<!--\s \{else\}\s -->/';     $_pattenEndif = '/<!--\s \{\/if\}\s -->/';     if (preg_match($_pattenif,$this->_tpl)) {       if (preg_match($_pattenEndif,$this->_tpl)) {         $this->_tpl = preg_replace($_pattenif,"<?php if (\$this->_vars['$1']){?>",$this->_tpl);         $this->_tpl = preg_replace($_pattenEndif,"<?php } ?>",$this->_tpl);         if (preg_match($_pattenElse,$this->_tpl)) {           $this->_tpl = preg_replace($_pattenElse,"<?php }else{?>",$this->_tpl);         }       }else{         echo 'ERROR:IF语句没有关闭!';       }     }   }接收模版文件内容后,构造方法,获取模版文件内容解析后用普通变量解析IF语句,之后解析模版文件生成编译文件。
【文件预览】:
php模版解析类
----php中文网下载站.url(114B)
----jiexi.php(3KB)
----php中文网免费下载站.txt(219B)

网友评论