-
-
异常代码
2016-11-10
- 模版编译(正则匹配替换)
$pattern='/'.this->lefttag;
$pattern .=' *$([a-zA-Z_]\w*) *';
$pattern .=this->righttag.'/';
Outhtml =preg_replace($pattern,"<?php echo this->getvar('$1') ?>",outhtml);
-
0赞 · 0采集
-
-
不当女神好多年
2016-08-18
- /模板引擎类--模板编译;通过$templateName去生成它的编译文件,默认为空
public function compileTemplate($templateName = null,$ext='.html'){
//先获取到当前处理的模板文件的名称,首先检测一下它是否为空,是则从私有成员中获取,否则就用用户输入的$templateName
$templateName = empty($templateName) ? $this->currentTemp : $templateName;
//核心代码,编译模板中需要用到的正则替换
-
0赞 · 0采集
-
-
ORCLee
2016-07-18
- $1:第一个子模式。相当于\\1。
-
截图
0赞 · 0采集
-
-
林静听蝉
2015-09-24
- //模板引擎类--模板编译;通过$templateName去生成它的编译文件,默认为空
public function compileTemplate($templateName = null,$ext='.html'){
//先获取到当前处理的模板文件的名称,首先检测一下它是否为空,是则从私有成员中获取,否则就用用户输入的$templateName
$templateName = empty($templateName) ? $this->currentTemp : $templateName;
//核心代码,编译模板中需要用到的正则替换
//定义一个正则表达式;这个$pattern就是一段可以匹配到模板中需要替换成变量的这么一个标记的正则表达式\{#\$(\w+)#\}
$pattern = '/'.preg_quote($this->leftTag);//左侧的\{#
$pattern .= ' *\$([a-zA-Z_]\w*) *';//中间的正则,为了给前端灵活的变量名书写方法,允许变量名前后有空格
$pattern .= preg_quote($this->rightTag).'/';//右侧的#}\
//需要对outputHtml,也就是从模板源文件中获取到的这段html代码中去寻找,用这个正则表达式去匹配这个标记,然后将它替换成我们想要的那种PHP代码,也就是PHP能够识别的那种变量的代码。
//使用preg_replace函数作一个正则的替换,$1表示使用这个$pattern匹配到的数据中的子模式,并且是第一个子模式
$this->outputHtml = preg_replace($pattern,'<?php echo $this->getVar(\'$1\') ?>',$this->outputHtml);
}
-
截图
1赞 · 4采集
-
-
lc_w
2015-08-17
- $replacement = '<?php echo $this->getVar(\'$1\')?>';
$1子模式
-
截图
0赞 · 0采集
-
-
lc_w
2015-08-17
- $pattern = '/'.preg_quote($this->leftTag);
$pattern .=' *\$([a-zA-Z_]\w*)*';
$pattern .= preg_quote($this->reghtTag).'/';
$this->outputHtml = preg_replace($pattern,'<?PP echo $this->getVar(\'$1\')?>?)',$thi->out
-
0赞 · 0采集
-
-
webwwb
2015-06-17
- $pattern = '/'.preg_quote($this->leftTag);
$pattern .=' *\$([a-zA-Z_]\w*)*';
$pattern .= preg_quote($this->reghtTag).'/';
$this->outputHtml = preg_replace($pattern,'<?PP echo $this->getVar(\'$1\')?>?)',$thi->out
-
0赞 · 2采集
-
-
慕名而来_向日葵
2015-05-30
- php 模板引擎 正则表达式
-
截图
0赞 · 1采集