preg_replace()函数的e修饰符在新版本的php7.0中过时了

这是原来过滤微信呢称的代码。

function getNickname($nickname){
    $tmpStr = preg_replace("#(\\\ud[0-9a-f]{3})|(\\\ue[0-9a-f]{3})#ie","",json_encode($nickname)); //将emoji的unicode置为空,其他不动
    $rs = json_decode($tmpStr, true);
    return $rs;
}


替换成下面这样即可
function getNickname($nickname)
{
    $tmpStr = preg_replace_callback("#(\\\ud[0-9a-f]{3})|(\\\ue[0-9a-f]{3})#i",function ($m) {
        return "";
    },json_encode($nickname)); //将emoji的unicode置为空,其他不动
    $rs = json_decode($tmpStr, true);
    return $rs;

}

猜你喜欢

转载自blog.csdn.net/tjls2008/article/details/83504483