Home >Backend Development >PHP Problem >How to solve the problem of Chinese garbled characters in pure PHP code

How to solve the problem of Chinese garbled characters in pure PHP code

藏色散人
藏色散人Original
2021-09-21 09:33:493623browse

The solution to the Chinese garbled code in pure PHP code is to add a line of code at the beginning of the PHP file as "header("content-type:text/html;charset=utf-8");".

How to solve the problem of Chinese garbled characters in pure PHP code

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

How to solve the problem of Chinese garbled code in pure PHP code?

Chinese garbled problem with pure PHP pages (the data is static)

<?php
header("content-type:text/html;charset=utf-8");         //设置编码

Related introduction: The

header() function sends the original HTTP header to the client.

It's important to realize that the header() function must be called before any actual output is sent (in PHP 4 and above, you can use output caching to solve this problem):

<html>
<?php
// 结果出错
// 在调用 header() 之前已存在输出
header(&#39;Location: http://www.example.com/&#39;);
?>

Syntax

header(string,replace,http_response_code)

Parameters

string Required. Specifies the header string to be sent.

replace

Optional. Indicates whether this header replaces the previous header, or adds a second header.

The default is true (replacement). false (allow multiple headers of the same type).

http_response_code Optional. Forces the HTTP response code to the specified value. (Available for PHP 4 and higher)

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to solve the problem of Chinese garbled characters in pure PHP code. 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