ECshop 解决Deprecated: preg_replace(): The /e modifier is depr

回覆文章
yehlu
Site Admin
文章: 3245
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

ECshop 解决Deprecated: preg_replace(): The /e modifier is depr

文章 yehlu »

http://www.jsjtt.com/kaiyuanjianzhan/ECSHOP/39.html

使用php5.5运行ecshop的时候出现如下错误Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in \ecshop\includes\cls_template.php on line 300

解决方法如下

打开ecshop的目录找到includes\cls_template.php 到第300行

代碼: 選擇全部

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

代碼: 選擇全部

return preg_replace_callback("/{([^\}\{\n]*)}/", function($r) { return $this->select($r[1]); }, $source);
重新运行问题以解决
官方说明http://www.php.net/manual/zh/reference.pcre.pa ... ifiers.php
yehlu
Site Admin
文章: 3245
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

Re: ECshop 解决Deprecated: preg_replace(): The /e modifier is

文章 yehlu »

主要集中在 upload/includes/cls_template.php 文件中:
1:line 300 :
原语句:
return preg_replace("/{([^\}\{\n]*)}/e", "\$this->select('\\1');", $source);
修改为:
return preg_replace_callback("/{([^\}\{\n]*)}/", function($r) { return $this->select($r[1]); }, $source);

2:line 495:
原语句:
$out = "<?php \n" . '$k = ' . preg_replace("/(\'\\$[^,]+)/e" , "stripslashes(trim('\\1','\''));", var_export($t, true)) . ";\n";
修改为:
$replacement = preg_replace_callback("/(\'\\$[^,]+)/" ,
function($matcher){
return stripslashes(trim($matcher[1],'\''));
},
var_export($t, true));
$out = "<?php \n" . '$k = ' . $replacement . ";\n";

3:line 554: //zuimoban.com 转载不带网址,木JJ

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

修改为:
$val = preg_replace_callback("/\[([^\[\]]*)\]/is",
function ($matcher) {
return '.'.str_replace('$','\$',$matcher[1]);
},
$val);

4:line 1071:

原语句:
$replacement = "'{include file='.strtolower('\\1'). '}'";
$source = preg_replace($pattern, $replacement, $source);

修改为:
$source = preg_replace_callback($pattern,
function ($matcher) {
return '{include file=' . strtolower($matcher[1]). '}';
},
$source);
回覆文章

回到「PHP」