美文网首页简友广场
php 获取微信昵称时 过滤特殊字符

php 获取微信昵称时 过滤特殊字符

作者: 七彩邪云 | 来源:发表于2020-01-05 20:19 被阅读0次

以下是处理微信昵称特殊字符的方法:

/**

* $str  微信昵称

**/

public function filter($str) {

    if($str){

    $name = $str;

$name = preg_replace('/\xEE[\x80-\xBF][\x80-\xBF]|\xEF[\x81-\x83][\x80-\xBF]/', '', $name);

$name = preg_replace('/xE0[x80-x9F][x80-xBF]‘.‘|xED[xA0-xBF][x80-xBF]/S','?', $name);

        $return = json_decode(preg_replace("#(\\\ud[0-9a-f]{3})#ie","",json_encode($name)));

        if(!$return){

            return $return;

        }

    }else{

        $return = '';

    }   

    return $return;

}

相关文章

网友评论

    本文标题:php 获取微信昵称时 过滤特殊字符

    本文链接:https://www.haomeiwen.com/subject/opucactx.html