【发布时间】:2015-04-19 12:56:44
【问题描述】:
在此函数中将 preg_replace 替换为 /e 修饰符到 preg_replace_callback 时遇到了一些问题:
private function parseFunctions() {
// replaces includes ( {include file="..."} )
while( preg_match( "/" .$this->leftDelimiterF ."include file=\"(.*)\.(.*)\""
.$this->rightDelimiterF ."/isUe", $this->template) )
{
$this->template = preg_replace( "/" .$this->leftDelimiterF ."include file=\"(.*)\.(.*)\""
.$this->rightDelimiterF."/isUe",
"file_get_contents(\$this->templateDir.'\\1'.'.'.'\\2')",
$this->template );
}
// deletes comments from the template files
$this->template = preg_replace( "/" .$this->leftDelimiterC ."(.*)" .$this->rightDelimiterC ."/isUe",
"", $this->template );
}
你能帮我解决这个问题吗?
编辑:
我设法修复了第二个,但另一个
{
$this->template = preg_replace_callback( "/" .$this->leftDelimiterF ."include file=\"(.*)\.(.*)\""
.$this->rightDelimiterF."/isU",
function(){$replacement="file_get_contents(\$this->templateDir.'\\1'.'.'.'\\2')";
return $replacement;},
$this->template );
}
没用。 我收到以下错误消息:
file_get_contents($this->templateDir.'\1'.'.'.'\2') file_get_contents($this->templateDir.'\1'.'.'.'\2') file_get_contents($this->templateDir.'\1'.'.'.'\2') file_get_contents($this->templateDir.'\1'.'.'.'\2') file_get_contents($this->templateDir.'\1'.'.'.'\2') file_get_contents($this-> templateDir.'\1'.'.'.'\2')
我对php还是比较陌生,所以我不知道如何处理这个问题。
【问题讨论】:
-
我不明白你在做什么,你为什么要在 while 中替换,然后在循环本身中替换。只需其中一个就足够了。
-
我也不确定。原来不是我写的,我只需要处理一下
-
那么您至少可以更好地解释问题所在吗?
-
问题是,/e 修饰符已被弃用(preg_replace():/e 修饰符已弃用,请改用 preg_replace_callback)。我正在尝试纠正代码中的一些问题,这些问题都留下了......
标签: php preg-replace preg-replace-callback