我的php文件编码和页面编码都是一致的,都是用的是UTF-8,数据库编码使用的UTF-8编码,但是在浏览器中显示数据库中信息时,汉字仍然是乱码,查看了很多网上的资料,都没找到真正的原因,还请高手指点啊啊啊啊啊!
我的这个问题貌似我的PHP文件中普遍存在,下面我简单举个打印试题库的例子:
源代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<title>打印题库</title>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
</head>
<?php
$conn=mysql_connect('localhost','root','222222');
$db=mysql_select_db('smarttest',$conn);
$result=mysql_query("select * from t_program");///查询题库表
mysql_query("set names GB2312");
$i=0;
while($record=mysql_fetch_array($result)){
$i++;
echo $record["N_PROG_ID "]."<br/>";
echo "题目".$i.":".$record["VC_PROG_CONTENT"]."<br/>";
echo "答案:".$record["VC_PROG_CODE "]."<br/>";
}
?>
网页显示结果如下:
17
题目1:???????jsValue(int m,int k,int xx[])??????????????m???m?k???????xx??
答案:
18
题目2:?????jsVal( )???????????????????0?2?4?6?8?????????????cnt????????????????????b??
答案:
19
题目3:?200???????????1000?9999?????ReadDat()???200???????aa???????jsSort()????????????????????????????????????????10????????b??????????????????????????
答案:
20
题目4:????????????????????????????????????
答案:
21
题目5:?100?????????????????????dm(???4?)?????mc(???10?)???dj(??)???sl(??)???je(???)???????????=??*?????????ReadDat()????100????????????sell???????SortDat()???????????????????????????????????????????????????????sell?
答案:
22
题目6:??????????????????????????????????
答案:
23
题目7:?????countValue()????????n??????n?????3?7??????????????s?????????
答案:
汉字描述部分显示全部都是乱码,研究了一下午也没找到真正原因,把我急坏了,请大虾们帮帮我!!!!