background
mobile devices often occur when users send content that contains emoji emoticons, unprocessed, and garbled when displayed.
Solution Solutions
1. Database support: Convert MySQL encoding from UTF8 to UTF8MB4.
2. Match emoji expression in content to filter or replace
/** * Expression Conversion update to ios9.2 covers encoding range * @param $str * @return mixed */public static function emoji_to_html ($STR) {$regex = '/([0 -9|#][\X{20E3}]) | [\x{00ae}|\x{00a9}|\x{203c}|\x{2047}|\x{2048}|\x{2049}|\x{3030}|\x{303d}|\x{2139}|\x{2122}|\x{3297}|\x{3299}] [\x{fe00}-\x{feff}]?| [\X{2190}-\X{21FF}] [\x{fe00}-\x{feff}]?| [\X{2300}-\X{23FF}] [\x{fe00}-\x{feff}]?| [\X{2460}-\X{24FF}] [\x{fe00}-\x{feff}]?| [\X{25A0}-\X{25FF}] [\x{fe00}-\x{feff}]?| [\X{2600}-\X{27BF}] [\x{fe00}-\x{feff}]?| [\x{2900}-\x{297f}] [\x{fe00}-\x{feff}]?| [\X{2B00}-\X{2BF0}] [\x{fe00}-\x{feff}]?| [\X{1F000}-\X{1F6FF}] [\x{fe00}-\x{feff}]?| [\X{1F900}-\X{1F9FF}] [\x{fe00}-\x{feff}]?/u '; $str = Preg_replace_callback ($regex, function ($matches) {$str = Json_encode ($matches [0]); $str = ''; return $str; }, $STR); return $STR;} Remove from database and back $string = Preg_replace_callback ('/<\/em>/is ', "Self::p Reg_emoji", $string);/** * output emoji expression * @param $matches * @return mixed */public static funct Ion Preg_emoji ($matches) {$str = $matches [0]; $str = Str_replace (' em: ', ' \u ', $str); return $str;}
3. directly filter out
/** * Filter Expression * @param $str * @return mixed */public static function Filter_emoji ($STR) { $regex = '/(\\\u[ed][0-9a-f]{3} )/I '; $str = Json_encode ($STR); $str = Preg_replace ($regex, ", $str); Return Json_decode ($STR);}
The above describes the PHP emoji expression processing, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.