Home > Backend Development > PHP Tutorial > The solution to Chinese garbled characters when outputting Chinese pages in PHP

The solution to Chinese garbled characters when outputting Chinese pages in PHP

不言
Release: 2023-04-04 06:28:01
Original
5927 people have browsed it

php The problem of Chinese garbled characters often occurs in PHP. Yesterday, I created a file in the local environment. The file encoding is in UTF-8 format. When I printed a simple statement, Chinese garbled characters appeared. It took me a long time to find it. The reason. Let’s solve this problem and record the solution here.

Garbled code problem:

Yesterday I wrote a very simple PHP output Chinese page, but a garbled code problem occurred. The first reaction may be that the encoding format of the script file is incorrect. Question, after looking at it, there is no problem. The original file is encoded as utf-8. What is the reason?

This is the first time I encountered this problem. Although you can add to the output page, It can be temporarily solved, but this method treats the symptoms rather than the root cause and cannot solve the problem at all. Later, I checked online and found that it was a problem with the default character settings of the php.ini configuration.

Solution:

Open the php.ini file, find; default_charset = "iso-8859-1", change it to: default_charset = "UTF-8" Remove the semicolon in front (remove the comment), change the character set to UTF-8, restart the apache service, refresh the page, and the Chinese display will be normal.

Related recommendations:

Solution to json_encode in php to deal with gbk and gb2312 Chinese garbled problems,

php json Chinese Garbled code processing method

The above is the detailed content of The solution to Chinese garbled characters when outputting Chinese pages in PHP. 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