There are several reasons for Chinese garbled characters on PHP pages. One is that the page encoding is not counted. The other is that no encoding is set in the database. The third is that there is a problem with apache encoding, the following two solutions are provided: Page encoding is not uniform.
Most of the garbled characters are caused by inconsistent encoding methods. There are four major inconsistencies that may exist:
1. The format of the webpage file (.html,. php, etc)
2. Specify the browser encoding method in html. head.
3. encoding for MySql database transmission
4. Apache Character Set
When a JS pop-up window is created on a page with only PHP code, if the pop-up window contains Chinese characters, garbled characters may occur,
Solution: one line of code:
Chinese garbled characters on the page
Copy codeThe Code is as follows:
Header ("Content-Type: text/html; charset = UTF-8 ");
The database is garbled
Copy codeThe Code is as follows:
. <? Php
Mysql_query ('set NAMES utf8 ');
// The next step is to find or modify the data and add
?>
Note:
1. This code must be placed at the top of the file, '<? After php;
2. The charset value depends on the code of the entire website. If it is gb2312, enter gb2312.