Linux php Chinese garbled Solution

Source: Internet
Author: User
Tags php mysql

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

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.