首页 >后端开发 >php教程 >Php实现csv写入下载

Php实现csv写入下载

不言
不言原创
2018-04-04 14:07:571464浏览

本篇文章的内容是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写入下载的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn