Php solves the problem of garbled characters in reading mysql Chinese data. 1. the encoding type of the PHP page language itself is not suitable. at this time, the Chinese text you write directly in the script must be garbled, not to mention the database solution: Select UTF8 or gb2312, which
1. the encoding type of the PHP page language itself is not suitable. at this time, the Chinese text you write directly in the script must be garbled, not to mention the database.
Solution:Select 'utf8' or 'gb2312', so that the client browser automatically selects and displays the correct Chinese characters. Note: Both 'utf8' and 'gb2312' can correctly display Chinese characters.
2. the encoding type in MySQL is incorrect.
Solution:When creating a database, select 'utf8' for the MySQL character set, and select utf8_general_ci for MySQL connection verification. in this way, it is certainly no problem that the created database is used to store Chinese characters,
Otherwise, your Chinese is garbled in MySQL first, and you should not expect it to be correctly displayed on the PHP page.
3. it depends on the script editing environment.For example, some content is written in word, some in notepad, and some in editplus, ultraplus, and other text editors. Sometimes I write Chinese directly in DW,
Solution:Try to use the same editor. If the original content is copied, we recommend that you use the encoding conversion function in ultraplus to convert it to utf8 or gb2312.
It doesn't matter what type to convert to. the key requirement is that the encoding in your php web application must be consistent.
4. when programming to access MySQL, it is recommended to add a line of code: mysql_query ("set names 'gbk '");
Solution: Select 'utf8' or 'gb2312...