Home  >  Article  >  Backend Development  >  What should I do if php prints out garbled characters?

What should I do if php prints out garbled characters?

藏色散人
藏色散人Original
2021-12-20 09:30:082222browse

Solution to garbled characters printed by php: 1. Open the corresponding PHP code file; 2. Add "header("content-type:text/html; charset=utf-8");" to the code. That’s it.

What should I do if php prints out garbled characters?

The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.

What should I do if php prints garbled characters?

php prints Chinese garbled characters

The text format of the php document is set to utf-8 format

Add

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

header in the code —Send native HTTP header

Description

header(string $string, bool $replace = true, int $response_code = ?): void

header() is used to send native HTTP header .

Please note that header() must be called before any actual output, whether it is ordinary HTML tags, empty lines, or spaces in file or PHP output. This is a common mistake. When accessing functions in other files through include, require, or other functions, if there are spaces or blank lines before header() is called. The same problem exists with separate PHP/HTML files.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What should I do if php prints out garbled characters?. 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