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

 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     }

 

posted @ 2017-12-07 13:52  人在征途1  阅读(315)  评论(0编辑  收藏  举报