PHP + MySQL storage data common Chinese garbled problem summary, _ PHP Tutorial

Source: Internet
Author: User
Summary of common Chinese garbled characters in PHP + MySQL storage data ,. Summary of common Chinese garbled characters in PHP + MySQL storage data. this example summarizes common Chinese garbled characters in PHP + MySQL storage data. For your reference, the details are as follows: PHP + MyS PHP + MySQL storage data common Chinese garbled problem summary,

This example summarizes common Chinese garbled characters in the storage data of PHP + MySQL. We will share this with you for your reference. The details are as follows:

Common causes of Chinese garbled characters in PHP + MySQL:

1. the encoding format of the MYSQL database is utf8. if the encoding format is different from that of the PHP webpage, Chinese characters in MYSQL may be garbled.

2. when creating a table in MYSQL or selecting a field, the setting type is not utf8, but the webpage encoding is not utf8, which may also cause MYSQL Chinese garbled characters.

3. the character set of the PHP page is inconsistent with the encoding of the database.

4. PHP connects to the MYSQL database. The operation is the encoding specified by the set statement and the page encoding. the PHP page encoding is inconsistent.

5. the HTML page code submitted by the user is inconsistent with the page code of the displayed data, which will certainly cause PHP page garbled characters.

Solution to Chinese garbled text:

1. webpage encoding settings. Generally, the file header in HTML codeAdding properties:

  

Ensure that the webpage is "UTF-8" encoded.

2. PHP code settings. Add the following code to the beginning of the php code:

header("Content-type: text/html;charset=utf-8");

The file to be saved must be encoded in UTF-8 (you can use EditPlus to open the settings, for example). This ensures that the file is also UTF-8 encoded.

3. set the field in the database to utf8_general_ci.

4. when connecting PHP to the database, set the field type to utf8 as follows:

Mysql_connect ('localhost', 'user', 'password'); mysql_select_db ('DB'); mysql_query ("set names utf8 "); // ** set the character set ** mysql_query (the SQL statement to be executed );

I hope this article will help you with php programming.

Summary, This article summarizes common Chinese garbled characters in the storage data of PHP + MySQL. For your reference, the details are as follows: PHP + MyS...

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.