What to do if php data is garbled?

coldplay.xixi
Release: 2023-03-02 17:44:01
Original
2515 people have browsed it

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)<meta charset='utf-8'> 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");
Copy after login

(2) Web page header file encoding

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

(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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template