Home >Backend Development >PHP Problem >What to do if php data is garbled?

What to do if php data is garbled?

coldplay.xixi
coldplay.xixiOriginal
2020-07-18 11:55:542554browse

Solutions to garbled data in php: 1. The PHP encoding is consistent with the MySQL encoding; 2. The characters are unified when the database is created; 3. The character set of the table is unified; 4. The encoding of the character set sent by the header header must be consistent with the database consistent.

What to do if php data is garbled?

Solution to garbled php data:

(1) HTML encoding is consistent with MySQL encoding;

(2) PHP encoding is consistent with MySQL encoding;

(3) The encoding of the character set sent by the header is consistent with the database

(4) The characters are unified when the database is created;

(5) The character set of the table is unified;

(6)9ae2728d4b2905501308be91cfba82f6 is consistent with the page text encoding;

(7) The character set for connection and verification must be unified;

(8) The character set of the result set must be unified;

Encoding example

(1) Header encoding

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

(2) Web page header file encoding

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

(3) Database, data table, row and column encoding are consistent

(4) Connection result, verification character set setting

Connect to MYSQL database through mysqli_set_charset('utf8')

Note: utf- 8Document encoding; utf8 is MySQL encoding.

Related learning recommendations: PHP programming from entry to proficiency

The above is the detailed content of What to do if php data is garbled?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn