Linux PHP Chinese garbled solution

Source: Internet
Author: User
Tags character set php mysql

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   
? > 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.