Home > Backend Development > PHP Problem > How to solve the problem of garbled Chinese characters in PHP?

How to solve the problem of garbled Chinese characters in PHP?

Guanhui
Release: 2023-03-03 06:06:01
Original
3194 people have browsed it

How to solve the problem of garbled Chinese characters in PHP?

#How to solve the problem of garbled Chinese characters in PHP?

1. When connecting to the database, set the character set to "utf8";

//mysql
mysql_query('SET NAMES utf8');
//mysqli
mysqli_set_charset($connect, 'utf8');
Copy after login

2. Use the "header()" function to set the "Content-Type" of the response header to "utf8";

header("Content-Type: text/html;charset=utf-8");
Copy after login

3. Check whether the database character set is "utf8", otherwise change it to "utf8".

What is utf8

UTF-8 (8 bits, Universal Character Set/Unicode Transformation Format) is A variable-length character encoding for Unicode. It can be used to represent any character in the Unicode standard, and the first byte in its encoding is still compatible with ASCII, so that the original software that processes ASCII characters can continue to be used without or with only a few modifications. Therefore, it has gradually become the preferred encoding for email, web pages, and other applications that store or transmit text.

Recommended tutorial: "PHP"

The above is the detailed content of How to solve the problem of garbled Chinese characters in PHP?. 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