最近服务器php版本升级到了 5.6 发现出了很多警告
preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead
那么 应该怎么办呢
其实 只要 把 preg_replace 里面 有 /e 修饰符的代码 修改成 preg_replace _callback 然后重新写下就好了
例子
比如说
preg_replace("/([A-Z])/e", "'_' . strtolower('\\1')", $str)
preg_replace_callback('/([A-Z])/',
function ($matches) {
return '_' . strtolower($matches[0]);
},
$str)即可
这里特别警告 修改后 /([A-Z])/e 最后一个 e 一定要去掉 不然就出错了
下面再看一个稍微复杂点的例子
$patterns = '/'.$begin.$parseTag.$n1.'\/(\s*?)'.$end.'/eis';
$replacement = "\$this->parseXmlTag('$tagLib','$tag','$1','')";
$content = preg_replace($patterns, $replacement,$content);$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);这里 用 $thit 代替 $this; 好了 今天先记录到这里吧 。
小烟原创,转载请注明出处!
原文地址:http://blog.csdn.net/ebw123/article/details/41958789