php - 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();
解决方案
推荐阅读
- javascript - 按时间排序json表
- grafana - 是否可以使用 grafana 将 SQL DB(postgres / mysql)的查询结果写入 influxDB ?
- javascript - 在数据表中始终将空值排序到顶部
- java - 如何更改我的语句以在哈希图中打印对象成员类型的频率?
- python - tmp 文件夹在 s3 存储桶中创建 [Errno 2] 没有这样的文件或目录:'/tmp/plain_file/7A50-99D2-24D9-42BF.tar':FileNotFoundError
- c++ - c++ std::vector 作为类方法的参数传递的函数
- python - 烧瓶运行无法识别 Windows 上的 python-dotenv
- excel - 使用多个条件计数
- sparql - 不一致的维基数据查询结果
- angular - angular 7 有 oboe.js 替代品吗?