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.
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!