Phpemoji facial expression processing

Source: Internet
Author: User
: 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.