This article is about how PHP export CSV file (code example), there is a certain reference value, the need for friends can refer to, I hope to help you.
/** If a large number of data exports support paging write * [downloaddate public export CSV] * @param string $name [file name] * @param array $header [Header] * @param array $data [data set] * @param $is _header [true or False table Header resolution Loop write problem] * @return array name[file name] filepath[file path] */public static functio N Downloaddata ($name = ", $header =array (), $data =array (), $is _header=true) {set_time_limit (0); Ini_set (' Memory_limit ', ' 2048M '); Header ("Content-type:application/vnd.ms-excel"); Header ("Content-disposition:filename=downloaded.pdf"); try {if (! $name | |! $data) {throw new badrequesthttpexception (' parameter not nullable '); } $filePath = "./temp/download/{$name}.csv"; $header = Implode (",", $header); $header = Iconv (' UTF-8 ', ' Gbk//ignore ', $header); $header = Explode (",", $header); $fp = fopen ($filePath, ' A + '); if (!empty ($header) && Is_array ($header) && $is _heAder) {fputcsv ($fp, $header); } foreach ($data as $row) {$str = Implode ("", $row); $str = Iconv (' UTF-8 ', ' Gbk//ignore ', $str); $str = Str_replace (",", "|", $STR); $row = Explode ("", $str); Fputcsv ($fp, $row); } unset ($data); if (Ob_get_level () >0) {Ob_flush (); } flush (); } catch (Exception $e) {throw new Badrequesthttpexception ($e->getmessage ());//Throw exception} return [' Fi Lepath ' =>ltrim ($filePath, "./"), ' name ' and ' = ' $name. CSV ',]; }