日期:2014-05-17  浏览次数:20532 次

php页面出现中文乱码情况,请解决方式
index.php文件代码
<html>
<head>
<title>留言板</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<body>
<center>
<h1>留言板</h1>
</center>
<table width="90%" border="0" align="center">
<tr>
<td>
<?php
$f=fopen("text.txt","a+");
$message=fread($f,filesize("text.txt"));
fclose($f);
print $message;
?>
</td>
</tr>
</table>
<center>
<a href="write1.php">写留言</a>
</center>
</body>
<html>
write1.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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />


<title>无标题文档</title>

</head>

<body>
<div align="center">
<?php
print "留言板";
?>
<form method="post" action="write.php">
<p align="center">请输入用户名:</p>
<input type="text" name="name">
<p align="center">请输入信箱:</p>
<p>
<input type="text" name="email">
</p>
<p align="center">请输入你的留言:</p>
<p>
<textarea name="note" cols="30" rows="5"></textarea>
</p>
<p>
<input type="submit" value="确定">
<input type="reset" value="取消">
</p>
</form>
</div>
</body>

</html>
write.php代码
<html>
<head>
<title>留言板</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<body>
<center>
<?php
$name=$_POST["name"];
$email=$_POST["email"];
$note=$_POST["note"];
if($name=="") print "请输入用户名!";
else if($email=="") print "请输入邮箱!";
else if ($note=="") print "请输入留言!";
else
{
$file=fopen("text.txt","a+");
$time=date("F j, Y, g:i a");  
$main="用户:<a href=\"mailto:$mail\">$name</a> $time<br>留言:$note<br>";
$write=fwrite($file,$main);
fclose($file);
print "<center>提交成功!</center></br>";
}
?>
<a href="write1.php">继续留言</a></br>
<a href="index.php">查看留言</a></br>
</center>
</body>
</html>
我3个文件都是gb2312编码啊,但是文本框中输入中文时还是会出现乱码
换成utf-8编码后,代码中的中文乱码,但是文本框中输入中文就不会了,求解释。


------解决方案--------------------
记事本 另存为 一下编码, 同 文件里的 charset 一致