How does PHP handle emoticon characters submitted by mobile terminals?

Source: Internet
Author: User
How does PHP handle emoticon characters submitted by mobile terminals? At present, mobile terminals provide a lot of emojis, such as those in Baidu's input method.
Many expressions are unidentifiable after they are obtained using php. when stored in mysql, the content starting from the expression position will be lost.

For example, if you enter the start content [emoticons] end content
When you use php to obtain and store data in mysql, you can only save: start content [


Is there any way to delete unrecognized emoticon without affecting the subsequent content?
For example, if the above expression cannot be identified, what you want to save to mysql is: start content [] end content


Reply to discussion (solution)

Set the mysql character set to utf8mb4.

If it is utf8_general_ci, can it be changed to utf8mb4 directly?
In addition, you cannot see utf8mb4 in myphpadmin. how can I modify it?

It seems that the version is not enough. it seems that you want to upgrade to version 5.5 or above, which is troublesome.

Do not upgrade
Before warehouse receiving
$ Text = preg_replace_callback ('/[\ xf0-\ xf7]. {3}/', function ($ r) {return' @ e '. base64_encode ($ r [0]) ;}, $ text );
After warehouse picking
$ Text = preg_replace_callback ('/@ E (. {6 }=)/', function ($ r) {return base64_decode ($ r [1]) ;}, $ text );

Do not upgrade
Before warehouse receiving
$ Text = preg_replace_callback ('/[\ xf0-\ xf7]. {3}/', function ($ r) {return' @ e '. base64_encode ($ r [0]) ;}, $ text );
After warehouse picking
$ Text = preg_replace_callback ('/@ E (. {6 }=)/', function ($ r) {return base64_decode ($ r [1]) ;}, $ text );



Thank you for your consideration.

Do not upgrade
Before warehouse receiving
$ Text = preg_replace_callback ('/[\ xf0-\ xf7]. {3}/', function ($ r) {return' @ e '. base64_encode ($ r [0]) ;}, $ text );
After warehouse picking
$ Text = preg_replace_callback ('/@ E (. {6 }=)/', function ($ r) {return base64_decode ($ r [1]) ;}, $ text );



I am not familiar with regular expressions and use the method given by the moderator. if I just want to filter out these emojis, then return will be written as return ''; is that all right?
Will some other symbols be removed?

$ Text = preg_replace_callback ('/[\ xf0-\ xf7]. {3}/', function ($ r) {return '';}, $ text );

$ Text = preg_replace_callback ('/[\ xf0-\ xf7]. {3}/', function ($ r) {return '';}, $ text );



Thank you, moderator.

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.