In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "the solution to the emoji expression problem in the php development". In the daily operation, I believe that many people have doubts about the solution to the emoji expression problem in the php development. The editor consulted all kinds of materials and sorted out the simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "the solution to the emoji expression problem in the php development". Next, please follow the editor to study!
Background
When doing Wechat development, you will find that storing Wechat nicknames is essential.
But this evil Wechat supports emoji emoji as a nickname, which hurts a little bit.
In general, Mysql tables are designed with the UTF8 character set. Insert the nickname field with emoji into it and it's gone, and the whole field becomes an empty string. What's going on?
It turns out that because Mysql's utf8 character set is 3 bytes and emoji is 4 bytes, the entire nickname cannot be stored. What are we going to do? Let me introduce some methods.
Solution
1. Use utf8mb4 character set
If your mysql version > = 5.5.3, you can directly upgrade utf8 to the utf8mb4 character set.
This 4-byte utf8 encoding is perfectly compatible with the old 3-byte utf8 character set and can store emoji expressions directly, so it is the best solution.
As for the performance loss caused by the increase in bytes, I have seen some evaluations, which are almost negligible
2. Use base64 coding
If you can't use utf8mb4 for some reason, you can also use base64 to save the country.
The emoji encoded with functions such as base64_encode can be directly stored in the data table of the utf8 byte set and can be decode when it is taken out.
3. Kill emoji emoji
Emoji emoticons are a troublesome thing, and even if you can store them, they may not display perfectly. On platforms other than iOS, such as PC or android. If you need to display emoji, you have to prepare a lot of emoji images and use third-party front-end class libraries. Even so, it is possible that emoji images cannot be displayed because they are not complete enough. In most business scenarios, emoji is not a must. We can properly consider killing it and save all kinds of costs.
After a lot of painstaking google, I finally found the code that works:
/ / filter out emoji emoji function filterEmoji ($str) {$str = preg_replace_callback ('/. / ugg, function (array $match) {return strlen ($match [0]) > = 4?': $match [0];}, $str); return $str;} so far, the study on "Solutions to emoji emoji problems in php development" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.