Home >Backend Development >PHP Problem >Chinese garbled characters in php file

Chinese garbled characters in php file

王林
王林Original
2019-09-18 13:04:305188browse

Chinese garbled characters in php file

In the PHP file, if the output part contains Chinese characters, if it is not processed properly, the problem of Chinese garbled characters may occur. To solve this problem, you can use the header() function.

1. Create a new PHP file and output the text at both ends, one section in English and one section in Chinese. Example:

Chinese garbled characters in php file

2. Save the above content and view the running results in the browser

Chinese garbled characters in php file

3. At this moment, PHP Chinese appears The problem of garbled characters is mostly caused by the inconsistency between the encoding of the file and the decoding of the browser. For example, the encoding format of the file just edited is UTF-8

Chinese garbled characters in php file

4. The browser incorrectly decodes the file content according to Simplified Chinese (GBK) encoding by default, so the problem of Chinese garbled characters appears

Chinese garbled characters in php file

5. Adjust the encoding format to the correct Unicode through the browser, and the Chinese

can be displayed correctly. Chinese garbled characters in php file

#6. However, the above problems cannot cure the problem of Chinese garbled characters in PHP. You can specify the encoding format through the header in the PHP file, and the browser can decode the file correctly. Example :

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

Chinese garbled characters in php file

Note: The header() function should be placed before any output content.

Recommended tutorial: PHP video tutorial

The above is the detailed content of Chinese garbled characters in php file. 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
Previous article:php cannot parseNext article:php cannot parse