Home > Article > Backend Development > How to solve the Chinese garbled problem of wamp php
wamp Solution to garbled Chinese characters in php: 1. Add the statement "header('Content-Type: text/html; charset=UTF-8');" to the php header; 2. Change the php file Stored in "UTF-8 BOM" format.
Recommendation: "PHP Video Tutorial"
I recently learned PHP again and found that echo is used every time in a PHP file. When the command outputs Chinese characters, garbled characters always appear. Pure HTML files will not appear garbled. After searching online for a long time, they all said that the problem is that meta does not write UTF-8. However, Force has clearly loaded the meta utf-8 code, but it is still garbled. Finally, I found the problem. It turned out to be a problem with the default character set of php.ini.
Generally, when using the UTF-8 character set, you only need to add the following characters to the page:
<meta charset="UTF-8">
If Chinese garbled characters appear, please refer to the following solutions
Temporary solution 1:
Add the following code to the php header
header('Content-Type: text/html; charset=UTF-8');
Temporary solution 2:
When saving the php file, it needs to be stored in UTF-8 BOM format. However, this method has a disadvantage. It can be tested locally, but garbled characters will appear when transmitted to the website.
Perfect solution 3:
Finally, I discovered that the default character set of the original local WAMP PHP.INI file had somehow changed to GBK. Change the file default character set to UTF-8. Perfect problem solving.
Find \wamp64\bin\php\php5.6.31\php.ini
Search for the relevant code and modify it as follows. Pay attention to the PHP version you are using. Different versions of php.ini In different folders
; PHP's default character set is set to UTF-8. ; http://php.net/default-charset default_charset = "UTF-8"
The above is the detailed content of How to solve the Chinese garbled problem of wamp php. For more information, please follow other related articles on the PHP Chinese website!