Ecshop如何解决Deprecated: preg_replace()报错

Posted 红尘书生

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ecshop如何解决Deprecated: preg_replace()报错相关的知识,希望对你有一定的参考价值。

今天安装Ecshop后,运行出现各种问题,其中 Deprecated: preg_replace() 之类的报错最多,下面贴出解决方案:

 

错误原因:

  preg_replace() 函数中用到的修饰符 /e 在 php5.5.x 中已经被弃用了。

  如果你的PHP版本恰好是PHP5.5.X,那你的ECSHOP肯定就会报类似下面这样的错误:

  Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in......

 

解决办法:

  1. Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in \includes\cls_template.php on line 300   

    原有内容:

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

    修改后内容:

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

 

  2. Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in \includes\cls_template.php on line 491 

    原有内容:

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

    修改后内容: 

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

 

  3. Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in \includes\cls_template.php on line 550

    原有内容:

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

    修改后内容:

      $val = preg_replace_callback(‘/\[([^\[\]]*)\]/is‘,function ($matches) {return ‘.‘.str_replace(‘$‘,‘\$‘,$matches[1]);},$val);

 

  4. Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in \includes\cls_template.php on line 1074

    原有内容:

      $source = preg_replace($pattern, $replacement, $source);

    修改后内容:

      $source = preg_replace_callback($pattern, function ($matches) { return ‘{include file=‘.strtolower($matches[1]). ‘}‘;},$source);

 

  5. Strict Standards: Only variables should be passed by reference in ...\upload\includes\lib_main.php on line 1329

    原有内容:

      $ext = end(explode(‘.‘, $tmp));

    修改后内容:

      $extsub = explode(‘.‘, $tmp);

      $tmp = end($extsub);

      $tmp = basename($tmp,".$ext");

 

最后,将错误修改后,上传到服务器.然后进入后台,清空缓存,刷新页面即可。

以上是关于Ecshop如何解决Deprecated: preg_replace()报错的主要内容,如果未能解决你的问题,请参考以下文章

解决Deprecated: preg_replace(): The /e modifier is deprecated, use

ecshop商城出现此问题怎么解决?求解!

解决php deprecated 的问题

ECshop在PHP5.3以上版本错误处理

ECshop 迁移到 PHP7版本时遇到的兼容性问题,ecshopphp7

ecshop首页如何调用分类下的子分类商品