Linux PHP Chinese garbled
In Ubuntu under the PHP page output garbled, in the case of not involving the database code:
modifying "/etc/php5/apache2/php.ini" will
The code is as follows |
Copy Code |
Default_charset = "Iso-8859-1" Amended to Default_charset = "Utf-8" |
And then restart Apache:
The code is as follows |
Copy Code |
Sudo/etc/init.d/apache2 restart |
PHP MySQL Chinese garbled
Generally speaking, for encoding compatibility, 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 "/> |
At this point, the normal display of Chinese needs to transform the encoding method, such as
The code is as follows |
Copy Code |
Echo iconv ("GB2312", "UTF-8", ' Chinese '); |
It won't be garbled.
There are other ways, such as
Add in front of the Echo in PHP
The code is as follows |
Copy Code |
Header ("content-type:text/html;charset=gb2312"); |
Of course the Simplified Chinese page can also be simply,
Put
The code is as follows |
Copy Code |
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/> |
The UTF-8 in the gb2312 is changed into
code is as follows |
copy code |
<?php mysql_query (' SET NAMES UTF8 '); The next step is to identify the data or modify it, add the ? > |