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

藏色散人
Release: 2023-03-12 19:42:01
Original
3589 people have browsed it

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");         //设置编码
Copy after login

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

Syntax

header(string,replace,http_response_code)
Copy after login

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!

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