Home >Backend Development >PHP Tutorial >How to solve the problem of Chinese garbled characters in php

How to solve the problem of Chinese garbled characters in php

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-08-08 09:34:071010browse



$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);
?>
Displayed as follows:
Resource id #1
dd:54
ddd:8
??:15
???:25
??:32
Mysql encoding: utf8, GBK have been tried. Both mysql font and command line display are correct.
Question added:
Garbled code:
???:15
???:25
??:32
In these lines, the values ​​in the database are Chinese characters. What is displayed is a question mark.

Solution:

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

The above introduces how to solve the problem of garbled Chinese characters in PHP, including the content of Chinese garbled characters in PHP. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn