: This article mainly introduces phpemoji facial expression processing. For more information about PHP tutorials, see. Background
Mobile devices often send emoji in the content they send. unhandled, garbled characters are displayed.
Solution
1. database support: converts Mysql encoding from utf8 to utf8mb4.
2. filter or replace the emoji in the matching content.
/*** Updated emoticon conversion to ios9.2, covering the 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 ;}retrieve from the database and convert back to $ string = preg_replace_callback ('/<\/Em>/is ', "self: preg_emoji", $ string ); /*** output emoji expression * @ param $ matches * @ return mixed */public static function preg_emoji ($ matches) {$ str = $ matches [0]; $ str = str_replace ('em: ',' \ U', $ str); return $ str ;}
3. directly filter out
/*** Filter emojis ** @ 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 introduces php emoji processing, including some content, and hope to be helpful to friends who are interested in PHP tutorials.