smarty如何完美兼容php5.5和preg_replace_callback如何替换preg_replace
  • 更新时间:2024-09-28 21:25:22
  • 网站建设
  • 发布时间:1年前
  • 347

现在PHP5.5版本出来了,我安装了一下,变化真的不小。我们使用的聪明人实际上是不兼容的。当我运行它时,出现以下错误:

preg_replace():

意思是用preg_replace_callback来替换preg_replace中的/e参数。可能是出于安全考虑,在php5.5中取消了这个参数,但是这个preg_replace_callback函数不好用,所以就用那个Smarty_Compiler.class。把php文件第270行$search.'e'中的preg_replace(e去掉,本来可以的,但是问题又出来了,这个问题出现的几率不大,就是写不出来smarty 模板中的php 标记代码:{php}{/php}。

无法用preg_replace_callback() 函数替换此preg_replace()。具体更换方法如下:

在Smarty_Compiler 类中添加一个方法:

函数回调源($匹配){

返回''.$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=preg_replace_callback($search,

array('self','callback_source')

, $源内容);

就这样,这样就可以完美兼容php5.5了。

本文发表于推来客网站制作公司

我们专注高端建站,小程序开发、软件系统定制开发、BUG修复、物联网开发、各类API接口对接开发等。十余年开发经验,每一个项目承诺做到满意为止,多一次对比,一定让您多一份收获!

本文章出于推来客官网,转载请表明原文地址:https://www.tlkjt.com/web/12822.html
推荐文章

在线客服

扫码联系客服

3985758

回到顶部