导出CSV表格数据

 <?php
 class Csv{
    //导出csv文件
    public function put_csv($list,$title){
        $file_name="CSV".date("mdHis",time()).".csv";
        header ( 'Content-Type: application/vnd.ms-excel' );
        header ( 'Content-Disposition: attachment;filename='.$file_name );
        header ( 'Cache-Control: max-age=0' );
        $file = fopen('php://output',"a");
        $limit=1000;
        $calc=0;
        foreach ($title as $v){
            $tit[]=iconv('UTF-8', 'GB2312//IGNORE',$v);
        }
        fputcsv($file,$tit);
        foreach ($list as $v){
            $calc++;
            if($limit==$calc){
                ob_flush();
                flush();
                $calc=0;
            }
            foreach ($v as $t){
                $tarr[]=iconv('UTF-8', 'GB2312//IGNORE',$t);
            }
            fputcsv($file,$tarr);
            unset($tarr);
        }
        unset($list);
        fclose($file);
        exit();
    }
 }

 $csv=new Csv(); //实例化一个类
 //$list=M("members")->field($field)->limit(10000)->select(); //内容
 //示例数组$list
 $list=array(array('id'=>1,'username'=>'zhangsan','email'=>'719907411@qq.com','phone'=>'13590381724','register_time'=>'2015年9月28日','register_ip'=>'192.168.11.137'));
 $csv_title=array('用户ID','用户名','绑定邮箱','绑定手机','注册时间','注册IP');//表格的标题
 $csv->put_csv($list,$csv_title);
 ?>

导出CSV表格数据

上一篇:Vmware9.0打开早期版本报错:this virtual machine’s policies are too old to be run by this version of vmware workstation”


下一篇:Java 容器在实际项目中的应用