Header("Content-type:application/vnd.ms-excel" ); Header("Content-disposition:filename=".Iconv("UTF-8", "GB18030", "Query_user_info"). ". csv" ); //open php file handle, php://output direct output to browser$fp=fopen(' Php://output ', ' a '); //convert Chinese title to code, otherwise garbledforeach($column _name as $i=$v) { $column _name[$i] =Iconv(' Utf-8 ', ' GB18030 ',$v); } //writes the title name through Fputcsv to the file handleFputcsv ($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); } //destroys data store variables already written to CSV, freeing up memory consumption unset($export _data); Ob_flush(); Flush(); } Exit();
Transferred from: http://blog.csdn.net/cdy102688/article/details/21395835
PHP exports a large amount of data with a CSV file