How to solve the problem of garbled WeChat nickname in PHP

藏色散人
Release: 2023-03-11 18:22:02
Original
5850 people have browsed it

php method to solve the garbled WeChat nickname: 1. Use decodeURIComponent to decode; 2. Database encoding, table encoding and corresponding storage fields use utf8mb4 encoding.

How to solve the problem of garbled WeChat nickname in PHP

The operating environment of this article: macOS10.15 system, PHP7.1 version, macbook air2017 computer

How does php solve the problem of garbled WeChat nicknames?

The first solution to solve the garbled Emoji expression

Encode the information containing the Emoji expression into encodeURIComponent and decode it in decodeURIComponent where it is used. This solution has been I personally tested it in the mini program "Garbage Classification Blackboard Report", as shown in the figure below:

How to solve the problem of garbled WeChat nickname in PHP

This solution is not good. It only solves the problem of garbled characters and brings The additional encoding and decoding overhead of the code is eliminated.

The second solution to solve the garbled Emoji expressions

According to my description using Mysql database and PHP YII2 framework

Two steps

Use utf8mb4 when connecting to the database. This is very important and easy to miss.

Database encoding, table encoding and corresponding storage fields should all use utf8mb4 encoding

The code example for the first step is as follows

How to solve the problem of garbled WeChat nickname in PHP

This solution is available for personal testing in the mini program "Group Blackboard".

How to solve the problem of garbled WeChat nickname in PHP

This solution is the most perfect solution, which does not bring additional code expenses. It is also the recommended solution that can be found online. However, in the actual operation process, Sometimes it may not take effect due to database version or personal settings, but this solution is really good.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to solve the problem of garbled WeChat nickname in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!