Analysis of php Chinese garbled characters and solutions causes of Chinese garbled characters mainly in character encoding settings;
First, you must select the correct character encoding when installing the mysql database. it is better to select UTF-8 for better insurance. If the installation is not correct, find the mysql installation directory, modify the character settings in the my. conf configuration file, and open the file, either under mysqll or under the server.
If the Chinese characters on the php page are garbled, the data is not queried by the database. if the static part of the HTML page is garbled, the header ("content-type: text/html; charset = utf8 ") to set the page encoding.
Possible commands:
1> database export command: mysql-u root-p database name> d: \ SQL. SQL
2> database import command: source D: \ SQL. SQL
3> mysql command for character set query: show variables like '% set % ';
4> mysql character set: set name utf8
[Note] do not use notepad to open databases exported from mysql, because Microsoft uses UTF-8 encoding instead of withoutBOM, which may cause problems.
If garbled characters are displayed in the data database, determine whether the data is exported from other versions of the database and imported into your own database. Because the mysql database server has different versions, direct data import may cause problems. For example, there is no problem in running Chinese characters locally in my mysql database, but when we Port the data to Sina SAE, we use phpmyadmin to import SQL data, because it is different from its mysql server version, although the UTF-8 character set has been selected during the import, it is no problem to view Chinese characters in phpmyadmin. However, when you open the page, all the data from the database is being investigated, all are garbled characters such as question marks.
The solution on the internet is to use mysql_query ("set name utf8") before executing each SQL statement. However, an error is reported when this statement is added. The final cause is that after mysql5.0, mysql functions are basically discarded, but their extension functions mysqli and mysqli_query ($ link, 'utf8') are used to set them so that Chinese garbled characters can be solved.
Another problem during this period is that if you do not need to upload data to the server, you can add some Chinese information again on the webpage, which can be displayed normally, however, if you use insert and statement to insert Chinese data directly in the database, the data still cannot be displayed normally. The specific problem is unknown. it is estimated that the database version is different.
The general solution is: correct database encoding, correct page encoding, and rigorous processing when php Data is inserted into the database. strict handling of possible problems.