thinkphp csv.class.php文件导出gb2312格式csv

本文介绍了一种使用PHP语言创建并导出CSV文件的方法。通过示例代码展示了如何设置HTTP头部信息来确保文件正确下载,并提供了处理数组数据以生成CSV格式内容的具体实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 1 function creatcsv($filename,$array)
 2     {
 3         @ini_set('display_errors',        0);
 4         header("Content-Disposition: attachment; filename=$filename.csv");
 5         header("Content-Transfer-Encoding: binary"); 
 6         header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
 7         header("Pragma: no-cache");
 8         header("Expires: 0");
 9         header('application/txt;charset=gb2312');
10         header( 'Content-Transfer-Encoding: binary' );
11         ob_clean();
12         //echo chr(0xFF).chr(0xFE);
13         if(is_array($array))
14         {
15             if(is_array(@$array[0]))
16             {
17                 foreach ($array as $tmp)
18                 {
19                     echo $this->est_iconv($this->charset, 'gb2312','"'.join('","',$tmp).'"');
20                     echo "\r\n";
21                 }
22             }
23             else
24             {
25                 echo $this->est_iconv($this->charset, 'gb2312', join(',',$array));
26             }
27         }
28         else
29         {
30             $this->ErrorMsg("param is not array");
31             return false;
32         }
33     }

 

转载于:https://www.cnblogs.com/shenaishiren/p/7998738.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值