[轉載] php用csv檔案匯出大量資料

來源:互聯網
上載者:User

標籤:excel   put   code   inf   否則   header   http   each   name   

header ( "Content-type:application/vnd.ms-excel" );  header ( "Content-Disposition:filename=" . iconv ( "UTF-8", "GB18030", "query_user_info" ) . ".csv" );    // 開啟PHP檔案控制代碼,php://output 表示直接輸出到瀏覽器  $fp = fopen(‘php://output‘, ‘a‘);     // 將中文標題轉換編碼,否則亂碼  foreach ($column_name as $i => $v) {           $column_name[$i] = iconv(‘utf-8‘, ‘GB18030‘, $v);       }     // 將標題名稱通過fputcsv寫到檔案控制代碼       fputcsv($fp, $column_name);    $pre_count = 10000;  for ($i=0;$i<intval($total_export_count/$pre_count)+1;$i++){      $export_data = $db->getAll($sql." limit ".strval($i*$pre_count).",{$pre_count}");      foreach ( $export_data as $item ) {          $rows = array();          foreach ( $item as $export_obj){              $rows[] = iconv(‘utf-8‘, ‘GB18030‘, $export_obj);          }          fputcsv($fp, $rows);      }            // 將已經寫到csv中的資料存放區變數銷毀,釋放記憶體佔用         unset($export_data);         ob_flush();         flush();  }    exit (); 

 

轉自: http://blog.csdn.net/cdy102688/article/details/21395835

[轉載] php用csv檔案匯出大量資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.