zoukankan      html  css  js  c++  java
  • 关于thinkhphp3.1中废弃 preg_replace /e 修饰符

    警告:preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead 

    网上查了下 发现 php5.5版本以上 就废弃了  preg_replace   函数中 /e 这个修饰符

    /e 这个修饰符的意思 就是让 正则替换的 时候 替换规则 支持 php 代码 

     

    解决方案:只要 把 preg_replace 里面 有 /e 修饰符的代码 修改成  preg_replace _callback  然后重新写下就好了 

    最简单的 写法:

    preg_replace("/([A-Z])/e", "'_' . strtolower('\1')", $str) 

    修改成

    preg_replace("/([A-Z])/",'gwyy', $str);  //在类中时写成:['gwyy'] 替换成 array($this,'gwyy')

    function gwyy($match) {  

      return  '_'.strtolower($match[1]);  

    }  

    preg_replace_callback('/([A-Z])/',  function ($matches) { 

       return '_' . strtolower($matches[0]);  

     },  $str)  

    使用了 类里面的自定义方法:

    $that = $this;   //这里 用 $that  代替 $this;  

    $patterns       = '/'.$begin.$parseTag.$n1.'/(s*?)'.$end.'/is';  

    $content=preg_replace_callback($patterns, function($matches) use($tagLib,$tag,$that){

      return $that->parseXmlTag($tagLib, $tag, $matches[1], ''); 

     }, $content);  

  • 相关阅读:
    使用控件的事件,动态创建控件
    C#委托和事件
    C# 静态类
    C# 饼形图
    (三)backbone
    (二)backbone
    (一)backbone
    (五)CodeMirror
    (二)CSS3应用
    (一)CSS3动画应用
  • 原文地址:https://www.cnblogs.com/feixiablog/p/8028631.html
Copyright © 2011-2022 走看看