Home >Backend Development >PHP Tutorial >phpmyadmin displays the problem of utf8_general_ci Chinese garbled characters, the final chapter_PHP tutorial
I have been writing PHP for more than a year, but the coding problem has not been solved well. My situation is like this,
The webpage display is completely normal. The Chinese garbled characters are displayed in the phpmyadmin database. Whether it is simplified or traditional, as long as it is Chinese, it is displayed in the following form: 梧州旅游
However, the webpage I wrote is displayed completely normally, whether it is Traditional Chinese or Simplified Chinese, there will be no garbled characters.
Of course, my webpage is saved in utf-8 format, and when I read the library, I added the statement mysql_query("set names 'utf-8'");, so what I see on the webpage is It is completely normal. Of course, it only displays garbled characters in phpmyadmin. If you see here that the web page is garbled, follow what I said, and save the web page in utf-8 format using Notepad, and then After specifying in the web page, add mysql_query("set names 'utf- 8'"); There will definitely be no garbled characters. Of course, databases, data tables, and fields must also be saved as utf8_general_ci encoding . Through the above operations, it will never appear on the web page. There will be garbled characters. What I am explaining here today is the problem of garbled characters displayed in phpmyadmin. This is the final article to solve the problem of garbled characters. After reading this article carefully, garbled characters will no longer appear. Appear in our programs and databases.
Okay, after reading the text part, you will definitely not have garbled characters when displayed on the web page. However, the Chinese characters displayed in phpmyadmin are still garbled. I spent a day to analyze my own code. , encoding format, and the encoding format of phpmyadmin. I searched GG and asked experienced technical personnel, but to no avail. Of course, it is better to ask for help than to ask for help. I slowly analyzed the encoding problem by myself, and finally found out why I was displaying garbled characters in phpmyadmin. Question, if you want to have a deeper understanding of encoding issues, so that garbled codes will no longer bother you in the future, you have to check these two differences: utf8 and utf-8, don’t look at them. It’s all the same, just one more line, one less line, will make your phpmyadmin garbled. Well, analyze your own garbled situation and change the red words. The following are the final methods to prevent garbled characters from appearing on the web page. Problem with garbled characters in phpmyadmin:
1 Use notepad to save all web pages as utf-8, as shown in the picture:
Note: ANSI is applicable to BIG5 and GBK
2 Specify the encoding format in your own web page. This is relatively simple. Not much to explain
3 Add mysql_query("set names 'utf8'") to the database operation; I can see clearly that it is utf8, not utf-8. For related information, use utf-8 in phpmyadmin It will be garbled characters. I have been writing programs by myself for more than a year. I have been using utf-8, which resulted in the format of garbled characters in phpmyadmin. Now I changed it back to utf8 and finally solved the problem of phpmyadmin displaying Chinese garbled characters. But there is one thing to pay attention to. After changing to utf8, the Chinese characters you previously entered will be garbled when read on the web page. If there is a lot of content, don’t change it. At most, phpmyadmin will be garbled, and the display on the web page will always be normal. Here, it is changed to utf8. When developing programs in the future, I will use this as a web page. All displays in phpmyadmin will be normal. For the garbled code problem, I would like to say 88.
4 The encoding format of the database is utf8_general_ci, the table format is also utf8_general_ci, and Chinese fields are also in utf8_general_ci,Look at phpmyadmin’s picture:
The above is the library and table load organized into utf8_general_ci, and then the field load Picture:
Okay, if you do these steps and use utf8 encoding, there will be no more garbled characters. Original article, please indicate that it is from Tengma PHP blog