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...