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

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

Guanhui
GuanhuiOriginal
2020-07-23 10:30:092984browse

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');

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

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

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!

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