php 导出csv

<?php
function exportCsv($data = []){
      set_time_limit(0);
        header("Content-type:text/csv");
        header("Content-Disposition:attachment;filename=导出".date('Y-m-d H:i:s').".csv");
        header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
        header('Expires:0');
        header('Pragma:public');
        $csvHeader = "列1,列2,列3\n";
        echo mb_convert_encoding($csvHeader, 'GBK', 'utf-8');
      
       foreach($data as $key => $value){
        $csvBody = $value[0];
        $csvBody .= $value[1];
        $csvBody .= $value[2];
        echo mb_convert_encoding($csvBody, 'GBK', 'utf-8');
      }
   
}

 

posted @ 2016-06-12 10:01  phpnaruto  阅读(67)  评论(0)    收藏  举报