Home  >  Article  >  Backend Development  >  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

怪我咯
怪我咯Original
2017-07-11 14:50:311459browse

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 '我是初学者';

A good thing to note is

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

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!

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