Home>Article>Backend Development> What to do if php prints out Chinese garbled characters

What to do if php prints out Chinese garbled characters

藏色散人
藏色散人 Original
2021-11-04 09:19:01 5268browse

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  这时候要正常显示中文需要转化一下编码方式,比如 echo iconv("GB2312","UTF-8",'中文');就不会乱码了 还有其他方法,比如 在php的echo前面加入header("Content-Type:text/html;charset=gb2312"); 当然简体中文页面也可以干脆地, 把中的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
Previous article:How to convert curl to php Next article:How to convert curl to php