<?php
header("Content-type: text/html; charset=utf-8");
$link=mysql_connect('localhost','root','');
if(!$link){
echo "连接失败<br>";
exit;
}echo "连接成功<br>";
mysql_select_db('dbphp',$link);
$sql="select id,name from db_shops";
$result=mysql_query($sql);
while($data=mysql_fetch_row($result)){
print_r($data);
echo "<br>";
}
mysql_close();
为什么添加了header()之后,echo输出的汉字就乱码,数据库查询的汉字正常显示。去掉header()之后,echo 输出正常,数据库的乱码?
哪位高手帮解答一下!!!
数据库编码都是utf8的,文件编码是指的哪个?
追答header里面设置了你文件内容的编码是uft-8,文件编码指的就是你的那个conn.php,你用记事本打开它,另存为,就会看到最底下有个编码,应该为utf-8,如果是ANSI就表示是中文编码。