ecshop在php5.6下的错误。

ChenRuiHua
  • 52

ecshop在php5.6下的错误。在5.3下是正常的。应该是PHP高版本函数变化了。

错误提示:

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/wwwroot/www.ufeelwine.com/includes/cls_template.php on line 1061

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/wwwroot/www.ufeelwine.com/includes/cls_template.php on line 483

具体网页地址:
http://www.ufeelwine.com/supplier.php?suppId=7

第483行:

                    $out = "<?php \n" . '$k = ' . preg_replace("/(\'\\$[^,]+)/e" , "stripslashes(trim('\\1','\''));", var_export($t, true)) . ";\n";
                    $out .= 'echo $this->_echash . $k[\'name\'] . \'|\' . serialize($k) . $this->_echash;' . "\n?>";

第1061行:

            $pattern     = '/<!--\s#BeginLibraryItem\s\"\/(.*?)\"\s-->.*?<!--\s#EndLibraryItem\s-->/se';
            $replacement = "'{include file='.strtolower('\\1'). '}'";
            $source      = preg_replace($pattern, $replacement, $source);

应该怎么改写呢?

回复
阅读 5.7k
3 个回答

<?php //cls_template.php
//-- 原本

return preg_replace("/{([^\}\{\n]*)}/e", "\$this->select('\\1');", $source);

//-- 修改成

return preg_replace_callback("/{([^\}\{\n]*)}/", function($r) { return $this->select($r[1]); }, $source);

//-- 原本

$val = preg_replace("/\[([^\[\]]*)\]/eis", "'.'.str_replace('$','\$','\\1')", $val);

//-- 修改成

$val = preg_replace_callback("/\[([^\[\]]*)\]/is", function($r) { return '.'.$r[1]; }, $val);

//-- 原本

$out = "<?php \n" . '$k = ' . preg_replace("/(\'\\$[^,]+)/e" , "stripslashes(trim('\\1','\''));", var_export($t, true)) . ";\n";

//-- 修改成

$out = "<?php \n" . '$k = ' . preg_replace_callback("/(\'\\$[^,]+)/" , function($r) { return stripslashes(trim($r[1],'\'')); }, var_export($t, true)) . ";\n";

//--- 原本

$pattern     = '/<!--\s#BeginLibraryItem\s\"\/(.*?)\"\s-->.*?<!--\s#EndLibraryItem\s-->/se';
$replacement = "'{include file='.strtolower('\\1'). '}'";
$source      = preg_replace($pattern, $replacement, $source);

//--- 修改成

$pattern     = '/<!--\s#BeginLibraryItem\s\"\/(.*?)\"\s-->.*?<!--\s#EndLibraryItem\s-->/s';
$replacement = function ($r) { return '{include file='.strtolower($r[1]). '}'; };
$source      = preg_replace_callback($pattern, $replacement, $source);
查尔斯
  • 8k

试试,没有环境没办法测试,根据提示信息改的

第483行:改成

$out = "<?php \n" . '$k = ' . preg_replace_callback("/(\'\\$[^,]+)/e" , function($r) { return stripslashes(trim('\\1','\'')); }, var_export($t, true)) . ";\n";

第1061行:改成

//$pattern     = '/<!--\s#BeginLibraryItem\s\"\/(.*?)\"\s-->.*?<!--\s#EndLibraryItem\s-->/se';
//$replacement = "'{include file='.strtolower('\\1'). '}'";
$source      = preg_replace('/<!--\s#BeginLibraryItem\s\"\/(.*?)\"\s-->.*?<!--\s#EndLibraryItem\s-->/se', function($r) { return '{include file='.strtolower('\\1'). '}';}, $source);
咪蛾
  • 2.5k

提示很清楚了啊
把preg_replace换成preg_replace_callback
看看preg_replace_callback的用法就明白了

/*
1、e参数去掉
2、后面的\1换成回调的数组对应的元素
*/
//483行
$out = "<?php \n" . '$k = ' . preg_replace_callback("/(\'\\$[^,]+)/" ,function($r) { return stripslashes(trim($r[1],'\'')); }, var_export($t, true)) . ";\n";
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏