Home>Article>Backend Development> PHP method to process WeChat nickname special symbol filtering

PHP method to process WeChat nickname special symbol filtering

coldplay.xixi
coldplay.xixi forward
2020-07-06 16:07:40 3516browse

PHP method to process WeChat nickname special symbol filtering

When we obtain WeChat nicknames through PHP and save them in the database, some nicknames cannot be saved because they have special symbols. At this time, we can handle it in the following way .

Method 2

protected function removeEmoji($clean_text) { // Match Emoticons $regexEmoticons = '/[\x{1F600}-\x{1F64F}]/u'; $clean_text = preg_replace($regexEmoticons, '', $clean_text); // Match Miscellaneous Symbols and Pictographs $regexSymbols = '/[\x{1F300}-\x{1F5FF}]/u'; $clean_text = preg_replace($regexSymbols, '', $clean_text); // Match Transport And Map Symbols $regexTransport = '/[\x{1F680}-\x{1F6FF}]/u'; $clean_text = preg_replace($regexTransport, '', $clean_text); // Match Miscellaneous Symbols $regexMisc = '/[\x{2600}-\x{26FF}]/u'; $clean_text = preg_replace($regexMisc, '', $clean_text); // Match Dingbats $regexDingbats = '/[\x{2700}-\x{27BF}]/u'; $clean_text = preg_replace($regexDingbats, '', $clean_text); return $clean_text; }

Method 2

preg_replace("/[\x{1F600}-\x{1F64F}\x{1F300}-\x{1F5FF}\x{1F680}-\x{1F6FF}\x{2600}-\x{26FF}\x{2700}-\x{27BF}]/u","","这里是昵称")

Method 3

// 过滤掉emoji表情 function filterEmoji($str){ $str = preg_replace_callback( '/./u', function (array $match) { return strlen($match[0]) >= 4 ? '' : $match[0]; }, $str); return $str; }

Related learning recommendations:PHP programming from entry to proficiency

The above is the detailed content of PHP method to process WeChat nickname special symbol filtering. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:liqingbo.cn. If there is any infringement, please contact admin@php.cn delete