Solutions to php garbled characters when reading mysql Chinese Data

Source: Internet
Author: User
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 '");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.