Php Chinese garbled characters are caused by many reasons. If it is linux, it may be caused by character encoding settings. If it is a page code garbled, we may be a page encoding problem. The solution is also very simple, here is a summary.
Linux php Chinese garbled characters
Php webpage output garbled characters in ubuntu, without involving database encoding:
Modify "/etc/php5/apache2/php. ini"
The Code is as follows: |
Copy code |
Default_charset = "iso-8859-1" Change Default_charset = "UTF-8" |
Restart apache:
The Code is as follows: |
Copy code |
Sudo/etc/init. d/apache2 restart |
Php mysql Chinese garbled characters
Generally, for encoding compatibility considerations, most pages define the page character set as UTF-8.
The Code is as follows: |
Copy code |
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/> |
To display Chinese characters properly, you need to convert the encoding method. For example:
The Code is as follows: |
Copy code |
Echo iconv ("GB2312", "UTF-8", 'Chinese '); |
It won't be garbled.
There are other methods, such
Before php echo, add
The Code is as follows: |
Copy code |
Header ("Content-Type: text/html; charset = gb2312 "); |
Of course, the simplified Chinese page can also be simply,
Set
The Code is as follows: |
Copy code |
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/> |
In the UTF-8 into gb2312
The Code is as follows: |
Copy code |
<? Php Mysql_query ('set NAMES utf8 '); The next step is to find data or modify and add ?> |