非常怪

t230angyong 2010-07-06 03:09:29
<?php
$file = fopen("liuyan.txt", "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
while(!feof($file))
{
echo fgets($file);
}

fclose($file);
?>

为什么输出来的内容是乱码,要怎么解决呀,急啊?
...全文
117 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
CunningBoy 2010-07-06
  • 打赏
  • 举报
回复
中文?

<?php
$file = fopen("liuyan.txt", "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
while(!feof($file)){
$string .= fgets($file);
}
fclose($file);
$chinese = iconv('ISO-8859-1', 'GB2312', $string);
echo $chinese;
?>
jlzan1314 2010-07-06
  • 打赏
  • 举报
回复
这个问题,应该有n个帖子说了嘛?

首先你php文件的编码要和txt统一,输出的时候header("charset=?")

红色部分是http头,你可以查下资料..
还是搜别人的帖子吧.
jianglin28290 2010-07-06
  • 打赏
  • 举报
回复
文件编码和页面编码不一致
用iconv转码试一下

21,893

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧