当前位置:Gxlcms > PHP教程 > Php实现csv写入下载

Php实现csv写入下载

时间:2021-07-01 10:21:17 帮助过:5人阅读

本篇文章的内容是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从数据库导出到.csv文件

以上就是Php实现csv写入下载的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行