大家好,最近遇到了一个棘手的问题,用php生成csv文件时 西欧字符显示成乱码, 请问怎样解决,谢谢。 下面是代码$URL="/CSVfiles.csv";
$content="Provence-Alpes-Côte";
file_put_contents($URL,$content);
header("Content-Type: application/force-download");
                        header("Content-Disposition: attachment; filename=".$URL."");
readfile($URL);下载的csv文件中字符   ô  显示的就是乱码,请问大家怎样正确显示,谢谢。

解决方案 »

  1.   

    function ConvertStringCharset($String){
        return iconv("ISO-8859-1","GB2312",$String);//转换成GB2312编码
    }$URL="/CSVfiles.csv"; 
    $content="Provence-Alpes-Côte"; 
    $content = ConvertStringCharset($content);
    file_put_contents($URL,$content); 
    header("Content-Type: application/force-download"); 
    header("Content-Disposition: attachment; filename=".$URL.""); 
    readfile($URL); 
    试试看
      

  2.   

    非常感谢  但还是不行  对了 我所有的文件都是uft-8编码  我用的是 MAC OS X 系统
      

  3.   

    gb2312不行的话,试试utf-8或者其他的
      

  4.   

    utf-8编码的文件,如果在linux下不是乱码,但是在windows平台下为乱码的话,
    需要在写文件内容前加上BOM头