在一些应用中emoji表情非但没有用,而且处理起来很麻烦。比如说,在手机端iso和安卓就不兼容,当然PC端就更加无法识别。因此为了数据统一,我们经常会吧emoji表情处理掉,下面的函数就是处理此标签的

 

/**
 * 过滤四个字节的emoji
 * @param string $text 要过滤的文本
 * @return string
 */
function filterEmoji($text)
{
    // Match Emoticons
    $regexEmoticons = '/[\x{1F600}-\x{1F64F}]/u';
    $text = preg_replace($regexEmoticons, '', $text);
    
    // Match Miscellaneous Symbols and Pictographs
    $regexSymbols = '/[\x{1F300}-\x{1F5FF}]/u';
    $text = preg_replace($regexSymbols, '', $text);
    
    // Match Transport And Map Symbols
    $regexTransport = '/[\x{1F680}-\x{1F6FF}]/u';
    $text = preg_replace($regexTransport, '', $text);
    
    // Match Miscellaneous Symbols
    $regexMisc = '/[\x{2600}-\x{26FF}]/u';
    $text = preg_replace($regexMisc, '', $text);
    
    // Match Dingbats
    $regexDingbats = '/[\x{2700}-\x{27BF}]/u';
    $text = preg_replace($regexDingbats, '', $text);
    
    $text = preg_replace_callback(
        '/./u',
        function (array $match) {
            return strlen($match[0]) >= 4 ? '' : $match[0];
        },
        $text);
    
    //去除空格
    if(!empty($text)){
        $text = str_replace(' ', '',$text);
    }

    return $text;
}

由于wp的支持不好,这里我就做一下截图

Comments are closed.

Post Navigation