search
HomeBackend DevelopmentPHP ProblemWhat to do if php prints out Chinese garbled characters

What to do if php prints out Chinese garbled characters

Nov 04, 2021 am 09:19 AM
phpGarbled characters

Solution to php printing Chinese garbled characters: 1. Open the php.ini file; 2. Find ";default.charset="UTF-8""; 3. Remove the semicolon in front; 4. Restart the apache service and refresh the page.

What to do if php prints out Chinese garbled characters

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

What should I do if php prints out Chinese garbled characters?

Solution to the Chinese garbled output from PHP

Recently, I discovered on Windows that the Chinese output from the PHP program was garbled.

I read a lot of posts and information that you can add on the page:

用echo输出的中文显示成乱码,
其实应该是各种服务器脚本都会遇到这个问题,
根本还是编码问题,
一般来说出于编码兼容考虑大多的页面都将页面字符集定义为utf-8
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
这时候要正常显示中文需要转化一下编码方式,比如
echo iconv("GB2312","UTF-8",&#39;中文&#39;);就不会乱码了
还有其他方法,比如
在php的echo前面加入header("Content-Type:text/html;charset=gb2312");
当然简体中文页面也可以干脆地,
把<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />中的UTF-8改成gb2312
 
实际中遇见奇怪的现象,
在本机服务器上正常显示的页面,传上服务器就echo出来乱码,
没仔细琢磨过这个缘由,因为通过iconv函数GB2312、UTF-8换换位置重新编码下就正常了,
不过估计肯定是APACHE,更确切说是PHP服务端的设置不同造成的,
看看PHP.INI应该就能解决。

Add echo iconv("GB2312","UTF-8",'Chinese'); or< ;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> will be more painful.

Finally, I saw that it might be a problem with the php.ini file configuration, so I opened the php.ini file and found;default.charset="UTF-8"--->default.charset="UTF-8" Remove the semicolon in front (remove the comment), restart the apache service, refresh the page, and the Chinese display will be normal.

Record it again, hope it can help friends who encounter the same problem!

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What to do if php prints out Chinese garbled characters. 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

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.