Home  >  Article  >  Backend Development  >  How to solve the Chinese garbled problem of wamp php

How to solve the Chinese garbled problem of wamp php

藏色散人
藏色散人Original
2020-08-08 09:31:023099browse

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.

How to solve the Chinese garbled problem of wamp php

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(&#39;Content-Type: text/html; charset=UTF-8&#39;);

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.

How to solve the Chinese garbled problem of wamp php

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&#39;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!

Statement:
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