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);  

  • 相关阅读:
    centos下安装mycat
    centos下安装MySQL5.7
    centos下yum安装wget失败
    开心消消乐刷金币
    myBatis获取批量插入数据的主键id
    nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
    Mac下安装JDK 6
    VI下删除所有内容
    Mac下lombok无法安装到eclipse mars
    WEB-INF目录下的文件访问权限
  • 原文地址:https://www.cnblogs.com/feixiablog/p/8028631.html
Copyright © 2011-2022 走看看