Home > Backend Development > PHP Problem > What should I do if the Chinese characters output by echo in PHP are garbled?

What should I do if the Chinese characters output by echo in PHP are garbled?

王林
Release: 2023-02-28 19:30:02
Original
5397 people have browsed it

What should I do if the Chinese characters output by echo in PHP are garbled?

The Chinese output by echo shows garbled characters, which is basically an encoding problem.

Generally speaking, for the sake of encoding compatibility, most pages define the page character set as utf-8

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Copy after login

At this time, to display Chinese normally, you need to convert the encoding method, such as

echo iconv("GB2312","UTF-8",&#39;中文&#39;);
Copy after login

This way there will be no garbled characters.

There are other methods, such as adding

header("Content-Type:text/html;charset=gb2312");
Copy after login

in front of php’s echo. For more related tutorials, please pay attention to php中文网.

The above is the detailed content of What should I do if the Chinese characters output by echo in PHP are garbled?. 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