昨天调试的已经可以显示中文了,电脑什么都没动,今天打开这个页面中文又成乱码了,
代码如下:
<?php
header('Content-type: text/html;charset=GB2312');
$con=mysql_connect("localhost","root","1");
if(!$con)
{
die("打开数据库失败".mysql_error());
}
mysql_select_db("UserInfo",$con);mysql_query("set names GB2312");
$resualt=mysql_query("select * from UserInfo");echo "<table border='1'><tr><td>ID</td><td>姓名</td><td>年龄</td></tr>";while($row=mysql_fetch_array($resualt))
{
echo "<tr>";
echo "<td>".$row["UserID"]."</td>";
echo "<td>".$row["UserName"]."</td>";
echo "<td>".$row["UserAge"]."</td>";
echo "</tr>";
}
echo "</table>";
?>请问是什么原因
代码如下:
<?php
header('Content-type: text/html;charset=GB2312');
$con=mysql_connect("localhost","root","1");
if(!$con)
{
die("打开数据库失败".mysql_error());
}
mysql_select_db("UserInfo",$con);mysql_query("set names GB2312");
$resualt=mysql_query("select * from UserInfo");echo "<table border='1'><tr><td>ID</td><td>姓名</td><td>年龄</td></tr>";while($row=mysql_fetch_array($resualt))
{
echo "<tr>";
echo "<td>".$row["UserID"]."</td>";
echo "<td>".$row["UserName"]."</td>";
echo "<td>".$row["UserAge"]."</td>";
echo "</tr>";
}
echo "</table>";
?>请问是什么原因
header('Content-Type:text/html;charset=GB2312');
避免乱码~~~~~~~~
header('Content-Type:text/html;charset=GB2312');这主要是你的数据库中的编码格式和页面的编码不相同,最好在创建数据库的时候就设置编码
或mysql_query("set name 'utf8'");