PHP page Chinese garbled analysis bitsCN. the reason why comphp garbled: the square format of the page file (.html ,. php, etc.), html. the browser encoding method, MySql database transmission encoding method, and Apache character set specified in head.
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
The code is as follows:
Header ("Content-Type: text/html; charset = utf-8 ");
The database is garbled
The code is as follows :. 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 ,' 2. the charset value depends on the code of the entire website. if it is gb2312, enter gb2312. BitsCN.com