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的

解决方案 »

  1.   

    加上 BOM 头在 header 函数后面加上
    echo "\xef\xbb\xbf";
      

  2.   


    $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"; 
      

  3.   

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

  4.   


    不好使啊,我从数据库里取出来的UTF-8格式的汉字,生成后还是乱码啊。
      

  5.   

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

  6.   


    $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"; 
      

  7.   


    能再详细点么,PHP不太懂