Home >Backend Development >PHP Problem >Solution to linux php.ini Chinese garbled characters

Solution to linux php.ini Chinese garbled characters

藏色散人
藏色散人Original
2021-05-08 09:42:072559browse

Linux php.ini Chinese garbled solution: first find and open the "php.ini" configuration file; then find the statement about character encoding settings; finally change "iso-8859-1" to "utf -8" is enough.

Solution to linux php.ini Chinese garbled characters

The operating environment of this article: windows7 system, php5 version, DELL G3 computer

Solution to Chinese garbled characters in Linux php Method

Today, when running the php program, garbled characters appeared 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.

                                                                                                                                                                                                                                                                    
## Recommended learning: "

PHP Video Tutorial

"

The above is the detailed content of Solution to linux php.ini 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