将preg_replace()替换为preg_replace_callback() [英] Replace preg_replace() to preg_replace_callback()

查看:212
本文介绍了将preg_replace()替换为preg_replace_callback()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$source = preg_replace('/&#(\d+);/me', "utf8_encode(chr(\\1))", $source);

上面的代码给出了不建议使用的警告.

The above code gives deprecated warning.

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in 

如何将preg_replace()替换为preg_replace_callback()?

How can I replace preg_replace() to preg_replace_callback() ?

推荐答案

在此处阅读文档,以下是preg_replace_callback的示例

Here is an example of preg_replace_callback

$source = preg_replace_callback('/&#(\d+);/m', function($matches){
   return utf8_encode(chr($matches[1]));
}, $source);

这篇关于将preg_replace()替换为preg_replace_callback()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆