search
HomeBackend DevelopmentPHP ProblemHow to solve the problem of Chinese garbled characters in pure PHP code

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),