本篇文章的内容是PHP实现CSV写入下载的代码,现在分享给大家,有需要的朋友也可以参考一下这篇文章的内容
$title1 = '年月\明细,月贷款额,月利润额,月理论回款额,月实际回款额,月未还款额,月客户总量'."\n";
header("Cache-Control: public");
header("Pragma: public");
header("Content-type:application/vnd.ms-excel");
$filename = $title;
header("Content-Disposition:attachment;filename=$filename.csv");
header('Content-Type:APPLICATION/OCTET-STREAM');
ob_start();
//linux系统编码转换
//$header_str = mb_convert_encoding ($title1,"gbk","utf-8");
//$csv_line_data = mb_convert_encoding ($csv_line_data,"gbk","utf-8");
//windwos编码转换
//由于gb2312支持的字比较少,导致有些无法识别的字直接去掉了,换成支持更多字的gbk
//$data = iconv("utf-8","gb2312//IGNORE",$data);
$header_str = iconv("utf-8","gbk//IGNORE",$title1);
$csv_line_data = iconv("utf-8","gbk//IGNORE",$csv_line_data);
//$header_str = iconv("utf-8", 'gbk', $title);
//$csv_line_data = iconv("utf-8", 'gbk//IGNORE', $csv_line_data);
ob_end_clean();
//写出
echo $header_str;
echo $csv_line_data;
相关推荐:
以上是Php实现csv写入下载的详细内容。更多信息请关注PHP中文网其他相关文章!