没有不值得去解决的问题,也没有不值得去学习的技术!

Store WeChat Nicknames in MySQL with PHP 5.6 base64_encode and Emoji Support

The WeChat nickname displayed on the web page is: 🌵yangqin🍬✨, which supports Emoji

1. Based on WeChat web authorization, the obtained nickname is: 🌵yangqin🍬✨, as shown in Figure 1:

Based on WeChat web authorization, the obtained nickname is: 🌵yangqin🍬✨
Based on WeChat web authorization, the obtained nickname is: 🌵yangqin🍬✨

2. The obtained WeChat user information is shown in Figure 2:

The obtained WeChat user information
The obtained WeChat user information

3. The first solution, to enable MySQL to support storing Emoji, is to change the collation to: utf8mb4_general_ci, as shown in Figure 3:

The first solution, to enable MySQL to support storing Emoji, is to change the collation to: utf8mb4_general_ci
The first solution, to enable MySQL to support storing Emoji, is to change the collation to: utf8mb4_general_ci

4. The SQL statement executed successfully, as shown in Figure 4:

The SQL statement executed successfully
The SQL statement executed successfully

5. It turned out that MySQL’s support for storing Emoji data was not yet complete, as shown in Figure 5:

It turned out that MySQL's support for storing Emoji data was not yet complete, the nickname is: ????yangqin????✨
It turned out that MySQL’s support for storing Emoji data was not yet complete, the nickname is: ????yangqin????✨

6. Finally, I decided to revert the collation to: utf8_general_ci, and encode the nickname using the PHP function base64_encode, as shown in Figure 6:

Finally, I decided to revert the collation to: utf8_general_ci, and encode the nickname using the PHP function base64_encode
Finally, I decided to revert the collation to: utf8_general_ci, and encode the nickname using the PHP function base64_encode

7. After encoding, the nickname data stored in MySQL is: 8J+MtXlhbmdxaW7wn42s4pyo, as shown in Figure 7:

After encoding, the nickname data stored in MySQL is: 8J+MtXlhbmdxaW7wn42s4pyo
After encoding, the nickname data stored in MySQL is: 8J+MtXlhbmdxaW7wn42s4pyo

8. If you need to display the WeChat nickname on a web page, you must use base64_decode to decode it, as shown in Figure 8:

If you need to display the WeChat nickname on a web page, you must use base64_decode to decode it
If you need to display the WeChat nickname on a web page, you must use base64_decode to decode it

9. The WeChat nickname displayed on the web page is: 🌵yangqin🍬✨, which supports Emoji, as shown in Figure 9:

The WeChat nickname displayed on the web page is: 🌵yangqin🍬✨, which supports Emoji
The WeChat nickname displayed on the web page is: 🌵yangqin🍬✨, which supports Emoji

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系