The following describes how php can solve the problem of garbled characters in reading mysql Chinese data. For more information, see
The following describes how php can solve the problem of garbled characters in reading mysql Chinese data. For more information, see
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' to display the correct Chinese characters in the browser. 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, website space, and utf8_general_ci for MySQL connection verification. The database created in this way is used to store Chinese characters. Hong Kong Space,
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 characters directly in DW, server space,
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 '");