How to solve php Chinese garbled characters

Source: Internet
Author: User
: This article mainly introduces how to solve php Chinese garbled text. if you are interested in PHP tutorials, please refer to it.



$ MySQL_server_name = 'localhost ';
$ Mysql_username = 'root ';
$ Mysql_passWord = '000000 ';
$ Mysql_database = 'Lib ';
$ Conn = mysql_connect ($ mysql_server_name, $ mysql_username, $ mysql_password, $ mysql_database );
$ SQL = "select name, age from mytb ";
PRint ($ conn );
$ Rs = mysql_db_query ("lib", "select * from mytb", $ conn );
Print ("\ n
");
While ($ row = mysql_fetch_object ($ rs )){
Print ($ row-> name. ":". $ row-> age ."
");
}
Mysql_close ($ conn );
?>
Shown as follows:
Resource id #1
Dd: 54
Ddd: 8
?? : 15
??? : 25
?? : 32
Mysql code: utf8, GBK all tried. Mysql font and command line display are correct.
Question added:
Garbled:
??? : 15
??? : 25
?? : 32
In these rows, the database value is Chinese characters, and the question mark is displayed.

Solution:

In $ rs = mysql_db_query ("lib", "select * from mytb", $ conn );
Add
Mysql_query ("set names gb2312"); or mysql_query ("set names gbk ");

The above section describes how to solve php Chinese garbled text, including php Chinese garbled text, and hopes to help those who are interested in PHP tutorials.

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.