过滤特殊字符(包括过滤emoji表情)

/**
     * 过滤特殊字符
     * @param $text
     * @return mixed
     */
    public static function filterSpecialChars($text)
    {
        //过滤emoji表情
        $a = json_encode($text);
        $b = preg_replace("/\\\ud([8-9a-f][0-9a-z]{2})/i", "", $a);
        $text = json_decode($b);

        //过滤特殊字符
        $pattern = "/[\x{3400}-\x{4DB5}\x{4E00}-\x{9FA5}\x{9FA6}-\x{9FBB}\x{F900}-\x{FA2D}\x{FA30}-\x{FA6A}\x{FA70}-\x{FAD9}\x{FF00}-\x{FFEF}\x{2E80}-\x{2EFF}\x{3000}-\x{303F}\x{31C0}-\x{31EF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3100}-\x{312F}\x{31A0}-\x{31BF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{31F0}-\x{31FF}\x{AC00}-\x{D7AF}\x{1100}-\x{11FF}\x{3130}-\x{318F}\x{4DC0}-\x{4DFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{2800}-\x{28FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{2700}-\x{27BF}\x{2600}-\x{26FF}\x{FE10}-\x{FE1F}\x{FE30}-\x{FE4F}0-9a-zA-Z—\x{21}-\x{7e}\x{00}-\x{ff}]/ui";
        $filterStr = preg_replace($pattern, '', $text);
        $filterPattern = addslashes("/" . $filterStr . "/ui");
        return preg_replace($filterPattern, '', $text);
    }

 

转载于:https://www.cnblogs.com/-mrl/p/7149107.html

你可能感兴趣的:(过滤特殊字符(包括过滤emoji表情))