Home  >  Article  >  Backend Development  >  How to solve linux php Chinese garbled characters

How to solve linux php Chinese garbled characters

藏色散人
藏色散人Original
2020-11-02 11:20:141873browse

Linux PHP Chinese garbled solution: first open the php.ini file; then find the location of "default_charset" and modify it; then remove the comment and change "iso-8859-1" to "utf -8"; finally restart apache.

How to solve linux php Chinese garbled characters

Recommended: "PHP Video Tutorial"

Today, when running the php program, this Garbled characters appear where Chinese characters should appear. Later, when I searched for a solution, I found that it was a problem with character encoding settings. Here are several solutions.

Without involving database encoding: we can modify the statement about character encoding settings in "/etc/php5/apache2/php.ini".

sudo vi /etc/php5/apache2/php.ini

After opening the file, press "/default_charset" to search,

Press the Enter key to find the location of default_charset and modify it.

Remove the comments, that is, remove the ";" and change iso-8859-1 to utf-8.

## Then restart Apache,

Sudo /etc/init.d/apache2 restart

Then in Firefox, enter your webpage address That's it.

The following are other methods, but I have not tried them. After all, the problem is solved. Provided for your reference.

(1) Generally speaking, for encoding compatibility reasons, most pages define the page character set as utf-8

At this time, to display Chinese normally, you need to convert the encoding method, such as

echo iconf("GB2312","UTF-8 ",'Chinese');

will not be garbled.

(2) Add

header("Content-Type:text/html;charset=gb2312");

(3) in front of the echo in php Of course, Simplified Chinese pages can also simply use

Change UTF-8 in to gb2312.

                                                                                                                                                                                                                                                                    



##

The above is the detailed content of How to solve linux php 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 close php warningNext article:How to close php warning