分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

关于thinkhphp3.1中废弃 preg_replace /e 修饰符

发布时间:2023-09-06 01:30责任编辑:蔡小小关键词:暂无标签

警告: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);  

关于thinkhphp3.1中废弃 preg_replace /e 修饰符

原文地址:http://www.cnblogs.com/feixiablog/p/8028631.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved