首页 > 解决方案 > MS EDGE 中文件名日文的 CSV 导出问题

问题描述

在此处输入图像描述

使用 PHP 导出 CSV 时出现问题,文件名使用日语,使用 MS EDGE 时变得混乱。

我写的这段代码:

$filename = $this->lang->line('UM000107R001').".csv"; //japan

ob_clean();
header('Content-Encoding: UTF-8');
header('Content-Type: text/csv; charset=utf-8' );
header('Content-Disposition: attachment; filename='.mb_convert_encoding($filename,"UTF-8"));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');

$fp = fopen('php://output', 'w');
//This line is important:
fputs( $fp, "\xEF\xBB\xBF" ); // UTF-8 BOM !!!!!

$header = array(
   mb_convert_encoding($this->lang->line('EI000107B089'),"UTF-8"),
);
fputcsv($fp,  $header);

foreach($data->result() as $key => $value){
   $body = array(
       mb_convert_encoding($value->ID,"UTF-8"),
   );

   fputcsv($fp,  $body);
}

fclose($fp);
ob_flush();

标签: phpcsvheaderexportencode

解决方案


推荐阅读