Solution to php linux garbled characters: First find and open the "php.ini" file; then press "/default_charset" to search; then find the location of "default_charset" and modify it; finally, change the "iso- 8859-1" can be changed to "utf-8".
Recommended: "PHP Tutorial"
Today, when running the php program, I should Garbled characters appear where Chinese appears. 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 enter your web page address in Firefox.
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 the sake of encoding compatibility, most pages define the page character set as utf-8
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
At this time, to display Chinese normally, you need to convert the encoding method, such as
echo iconf("GB2312","UTF-8",'中文');
It won’t be garbled.
(2) Add
header("Content-Type:text/html;charset=gb2312");
in front of the echo in php (3) Of course, the simplified Chinese page can also simply add
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 中的UTF-8改成gb2312。
The above is the detailed content of How to solve the garbled problem of php linux. For more information, please follow other related articles on the PHP Chinese website!