What should I do if php prints out garbled characters?

藏色散人
Release: 2023-03-14 14:22:02
Original
2235 people have browsed it

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

header in the code —Send native HTTP header

Description

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

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!

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