Preg_replace-ecshop the error under php5.6.

Source: Internet
Author: User
Keywords Php ecshop preg_replace preg_replace_callback
Tags deprecated
Ecshop the error under php5.6. Under 5.3 is normal. The PHP high-version function should be changed.

Error message:

Deprecated:preg_replace (): the/e modifier is Deprecated, use Preg_replace_callback instead IN/HOME/WWWROOT/WWW.UFEELWI ne.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.UFEELWI ne.com/includes/cls_template.php on line 483

Specific webpage address:
Http://www.ufeelwine.com/supplier.php?suppId=7

Line No. 483:

                    $out = "
  
   _echash . $k[\'name\'] . \'|\' . serialize($k) . $this->_echash;' . "\n?>";

Line 1061th:

            $pattern     = '/
  
   .*?
  
   /se';            $replacement = "'{include file='.strtolower('\\1'). '}'";            $source      = preg_replace($pattern, $replacement, $source);

How should it be rewritten?

Reply content:

Ecshop the error under php5.6. Under 5.3 is normal. The PHP high-version function should be changed.

Error message:

Deprecated:preg_replace (): the/e modifier is Deprecated, use Preg_replace_callback instead IN/HOME/WWWROOT/WWW.UFEELWI ne.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.UFEELWI ne.com/includes/cls_template.php on line 483

Specific webpage address:
Http://www.ufeelwine.com/supplier.php?suppId=7

Line No. 483:

                    $out = "
  
   _echash . $k[\'name\'] . \'|\' . serialize($k) . $this->_echash;' . "\n?>";

Line 1061th:

            $pattern     = '/
  
   .*?
  
   /se';            $replacement = "'{include file='.strtolower('\\1'). '}'";            $source      = preg_replace($pattern, $replacement, $source);

How should it be rewritten?

-Originally

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

-Modified into

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

-Originally

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

-Modified into

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

-Originally

$out = "
  
   

//-- 修改成

$out = " 

//--- 原本

$pattern = '/ .*? /se';$replacement = "'{include file='.strtolower('\\1'). '}'";$source = preg_replace($pattern, $replacement, $source);

//--- 修改成

$pattern = '/ .*? /s';$replacement = function ($r) { return '{include file='.strtolower($r[1]). '}'; };$source = preg_replace_callback($pattern, $replacement, $source);

Try, no environment no way to test, according to the information changed

Line No. 483: Change to

$out = "
  
     

第1061行:改成

//$pattern = '/ .*? /se';//$replacement = "'{include file='.strtolower('\\1'). '}'";$source = preg_replace('/ .*? /se', function($r) { return '{include file='.strtolower('\\1'). '}';}, $source);

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

/*1、e参数去掉2、后面的\1换成回调的数组对应的元素*///483行$out = "
   
      
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.