How does PHP handle the emoji characters submitted by mobile?

Source: Internet
Author: User
Now the mobile side provides a lot of expressions, such as Baidu Input method in the expression.
A lot of expressions in PHP, after it is not recognized content, when stored in MySQL, it will start from the expression position, the contents of the back will be lost.

such as user input: Start content [Emoticons] End content
Get it in PHP and save it in MySQL only: start content [


Is there any way to remove these unrecognized expressions without affecting the content behind them?
For example, if the expression above is not recognized, it also wants to be able to be stored in MySQL: start content [] End content


Reply to discussion (solution)

Required to set the MySQL character set to Utf8mb4

If it is utf8_general_ci, can it be changed directly to UTF8MB4?
In addition, in myphpadmin, can not see UTF8MB4, how to change?

Seems to be the version is not enough, it seems to upgrade to more than 5.5, good trouble ah

No upgrade is OK
Before warehousing
$text = Preg_replace_callback ('/[\xf0-\xf7].{ 3}/', function ($r) {return ' @E '. Base64_encode ($r [0]);}, $text);
After the library
$text = Preg_replace_callback ('/@e (. { 6}==)/', function ($r) {return Base64_decode ($r [1]);}, $text);

No upgrade is OK
Before warehousing
$text = Preg_replace_callback ('/[\xf0-\xf7].{ 3}/', function ($r) {return ' @E '. Base64_encode ($r [0]);}, $text);
After the library
$text = Preg_replace_callback ('/@e (. { 6}==)/', function ($r) {return Base64_decode ($r [1]);}, $text);



Thank you moderator, I try

No upgrade is OK
Before warehousing
$text = Preg_replace_callback ('/[\xf0-\xf7].{ 3}/', function ($r) {return ' @E '. Base64_encode ($r [0]);}, $text);
After the library
$text = Preg_replace_callback ('/@e (. { 6}==)/', function ($r) {return Base64_decode ($r [1]);}, $text);



Not familiar with the regular expression, with the moderator of the method, if I just want to filter out these emoticons, then return to write a return ';
Will you remove some of the other symbols?

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

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



Roger that, thanks. 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.