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