PHP从MySQL读取数据输出乱码
MySQL如图所示:



PHP文件如下:
header("Content-Type: text/html; charset=utf-8");
$index = 0;
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
mysql_query("set names ’utf8’");
mysql_query("set character_set_client=utf8");
mysql_query("set character_set_results=utf8");
$result = mysql_query("SELECT * FROM test_list
limit 0,4");
while($row = mysql_fetch_array($result))
{
$load_crouse_array[$index] = array(
'Subject_ID' => $row['Subject_ID'],
'Subject_title' => $row['Subject_title'],
'Subject_url' => $row['Subject_url'],
'Subject_belong' => $row['Subject_belong'],
'Creat_time' => $row['Creat_time']
);
$index++;
}
mysql_query("INSERT INTO `test`.`test_list` (`Subject_ID`, `Subject_title`, `Subject_url`, `Subject_belong`, `Creat_time`) VALUES ('100005', '测试文本', 'test_url', 'excel_crous', '2014-08-10');");
echo json_encode($load_crouse_array);
echo "test Chinese 测试中文";
?>
最后输出结果如图所示:

同时插入的记录在数据库中中文部分也是显示为????。
本人使用Eclipse编程出现此问题,后直接使用文本编辑软件Notepad++同样存在此问题。环境为windows7,XMAPP,使用chrome浏览器。
------解决方案--------------------
这个不是乱码这个是你用json加密的,你要查看的话在输出的时候再解密就是了。
------解决方案--------------------你这个$load_crouse_array数组经过json_encode处理之后的数据,不是什么乱码,而是中文被unicode处理。
输出print_r($load_crouse_array);这个就知道是否乱码。