Chinese garbled characters in php file

王林
Release: 2023-02-24 11:14:01
Original
5149 people have browsed it

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");
Copy after login

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!

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