php生成txt文件问题

桾楉叁杄 2011-01-09 06:38:54
header("Content-Type: application/octet-stream");
header('Content-Disposition: attachment; filename="' . $filename . '"');
echo "test1";
echo "test1";
echo "test1";
echo "test1";
echo "test1";
echo "\r\n";

这种生成方式如何生成为UTF-8格式的txt文件呢?

我生成的都是ansi的
...全文
355 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
桾楉叁杄 2011-01-10
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 ihefe 的回复:]

PHP code

$filename="test.txt";
header("Content-Type: text");
//header('Content-Disposition: attachment; filename="' . $filename . '"');
echo "test1";
echo "test1";
echo "test1";
echo "test1";
echo ……
[/Quote]

不好使,全是乱码
桾楉叁杄 2011-01-10
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 jlzan1314 的回复:]

加上 BOM 头

在 header 函数后面加上
echo "\xef\xbb\xbf"; 数据库汉字部分 用iconv()转
[/Quote]

能再详细点么,PHP不太懂
ihefe 2011-01-10
  • 打赏
  • 举报
回复

$filename="test.txt";
header("Content-Type: text");
//header('Content-Disposition: attachment; filename="' . $filename . '"');
echo "test1";
echo "test1";
echo "test1";
echo "test1";
echo "test1";
echo "\r\n";
jlzan1314 2011-01-10
  • 打赏
  • 举报
回复
加上 BOM 头

在 header 函数后面加上
echo "\xef\xbb\xbf"; 数据库汉字部分 用iconv()转
桾楉叁杄 2011-01-10
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 free999 的回复:]

header("Content-Type:text/html;charset=UTF-8");
[/Quote]

不好使啊,我从数据库里取出来的UTF-8格式的汉字,生成后还是乱码啊。
free999 2011-01-10
  • 打赏
  • 举报
回复
header("Content-Type:text/html;charset=UTF-8");
ihefe 2011-01-10
  • 打赏
  • 举报
回复

$filename="test.txt";
header("Content-Type: text");
header('Content-Disposition: attachment; filename="' . $filename . '"');
echo "test1";
echo "test1";
echo "test1";
echo "test1";
echo "test1";
echo "\r\n";

xuzuning 2011-01-10
  • 打赏
  • 举报
回复
加上 BOM 头

在 header 函数后面加上
echo "\xef\xbb\xbf";
老骥伏枥 2011-01-09
  • 打赏
  • 举报
回复
第一次做沙发,不过我也来听听大家的说法的。

21,886

社区成员

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

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