Home > Backend Development > PHP Tutorial > What should I do if the Chinese characters in php are garbled? How to make the browser automatically recognize utf-8 encoding

What should I do if the Chinese characters in php are garbled? How to make the browser automatically recognize utf-8 encoding

怪我咯
Release: 2023-03-13 15:16:01
Original
1505 people have browsed it

PHP Chinese garbled characters are generally caused by character set problems. The encoding mainly has the following problems.

PHP+MySQLWhen doing website development, we usually encounter garbled characters when the browser outputs Chinese characters. The reason for this problem is mainly due to HTML content encoding, PHP file encoding and mysql databaseThe encoding is caused by the inconsistency among the three. Let's take UTF-8 as an example to briefly describe how to unify the relationship between the three. The solution is very simple, just add header
to php. Example:

header("Content-type: text/html; charset=utf-8"); 
echo '我是初学者';
Copy after login

A good thing to note is

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

No content can be output to the page before a sentence, which means that echo and other statements cannot be used, and html tags or text

cannot be output.

The above is the detailed content of What should I do if the Chinese characters in php are garbled? How to make the browser automatically recognize utf-8 encoding. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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