smarty如何完美兼容php5.5和preg_replace_callback如何替换preg_replace

现在php5.5版本出来了,我装了一下改动还真不小,咱们用的smarty居然不兼容了,一运行出现以下错误:
意思是说用preg_replace_callback来代替preg_replace里的/e参数,可能是因为安全性的考虑,在php5.5中把这个参数取消了,但是这个preg_replace_callback函数用起来不顺手,我就把那个smarty_compiler.class.php文件里的第270行里的preg_replace($search.'e'里的e去掉了,果然好了,可是问题又出来了,这个问题出来的几率不多,就是无法在smarty模板里写入php标签代码:{php}{/php}。
没办法还是要把这个preg_replace()用preg_replace_callback()函数来替换,具体替换方法如下:
在smarty_compiler这个类里加入一个方法:
function callback_source($matches){
return "".$this->_quote_replace($this->left_delimiter)."php".str_repeat("n",substr_count("","n"))."".$this->_quote_replace($this->right_delimiter)."";
}
然后在第270行左右找到:
$source_content = preg_replace($search.'e', "'"
. $this->_quote_replace($this->left_delimiter) . 'php'
. "' . str_repeat("n", substr_count('\0', "n")) .'"
. $this->_quote_replace($this->right_delimiter)
. "'"
, $source_content);
替换成:
$source_content = preg_replace_callback($search,
array("self","callback_source")
, $source_content);
即可,这样就可以完美兼容php5.5了。
上一个:网站制作公司哪家好,从综合方面判断
下一个::浅谈网站建设的站内链接优化
户县网站建设,户县做网站,户县网站设计