Mysql-How to Use PHP to match and replace iOS-standard emoji

Source: Internet
Author: User
I have encountered a problem. To save the emoji expression output from iOS keyboard to MySQL, I know that blob + utf8 can be used. But now my table is too big to change the type. So I want to match the emoji, replace it, and save it. However, the iOS keyboard input emoji table... encountered a problem. To store the emoji output from the iOS keyboard to MySQL, I know that blob + utf8 can be used. But now my table is too big to change the type. So I want to match the emoji, replace it, and save it.
However, the emoji input on the iOS keyboard is not standard. 0xe001- 0xe537This is changed.
For example, for the first laugh expression, the standard emoji unicode is 0xe415The iOS keyboard outputs 0xd83dxde04Two.
I use preg_match () for matching.

preg_match('/\\x{d83d}\\x{de04}/', $str_with_emoji_emotion, $matches);var_dump($matches);

The output is NULL.

How can I match such emojis...

Supplement: I used preg_match ('/[\ x {0000}-\ x {FFFF}]/U', $ str_with_emoji_emotion, $ matches). None of them match... I suspect this is the problem of emojis. Continue to study... Continue solving...

Supplement 2: Get it done today, do the bin2hex transcoding http://jiajun.org/g/emoji_encoder.php

Reply content:

I have encountered a problem. To save the emoji expression output from iOS keyboard to MySQL, I know that blob + utf8 can be used. But now my table is too big to change the type. So I want to match the emoji, replace it, and save it.
However, the emoji input on the iOS keyboard is not standard.0xe001-0xe537This is changed.
For example, for the first laugh expression, the standard emoji unicode is0xe415The iOS keyboard outputs0xd83dxde04Two.
I use preg_match () for matching.

preg_match('/\\x{d83d}\\x{de04}/', $str_with_emoji_emotion, $matches);var_dump($matches);

The output is NULL.

How can I match such emojis...

Supplement: I used preg_match ('/[\ x {0000}-\ x {FFFF}]/U', $ str_with_emoji_emotion, $ matches). None of them match... I suspect this is the problem of emojis. Continue to study... Continue solving...

Supplement 2: Get it done today, do the bin2hex transcoding http://jiajun.org/g/emoji_encoder.php

Finished today, made the bin2hex transcode http://jiajun.org/g/emoji_encoder.php

Try this

preg_match('/\x{d83d}\x{de04}/u', $str_with_smail_emotion, $matches);

In fact, there is already an open-source Conversion Program.
Http://code.iamcal.com/php/emoji/
Https://github.com/iamcal/php-emoji

I hope this will help you.
Http://stackoverflow.com/questions/12807176/php-writing-a-simple-removeemoji-function #

Http://www.bubuko.com/infodetail-1022211.html reference this article
A formula is derived, which converts 0xd83d0xde04 to 1f604, while U + 1F604 is the uniform smiling face code.
In this article, JavaScript Functions are used. I extracted several key lines of code and converted them into PHP Code as follows:

$ H = 0xd83d; // high
$ L = 0xde04; // low
$ Code = ($ h-0xD800) x 0x400 + 0x10000 + $ l-0xDC00; // Conversion Algorithm
Echo "U +". strtoupper (dechex ($ code ));
// The echo result is U + 1F604.

In addition, @ seeyoup has already mentioned the conversion of different encoding methods.

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.