Php: how to read mysql Chinese data with garbled characters _ PHP Tutorial

Source: Internet
Author: User
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...

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.