我正在使用此代码生成CSV – 我正在使用codeigniter框架
$array = array( array( (string)'XXX XX XX',(string)'3',(string)'68878353',(string)'',(string)'xxxx@xxxx.xxx.xx',),); $this->load->helper('csv'); array_to_csv($array,'blueform.csv');
输出我得到:
"XXX XX XX",3,68878353,xxxx@xxxx.xxx.xx
预期产量:
"XXX XX XX","3","68878353","","xxxx@xxxx.xxx.xx"
array_to_csv的代码
if (!function_exists('array_to_csv')) { function array_to_csv($array,$download = "") { if ($download != "") { header('Content-Type: application/csv'); header('Content-Disposition: attachement; filename="' . $download . '"'); } ob_start(); $f = fopen('PHP://output','w') or show_error("Can't open PHP://output"); $n = 0; foreach ($array as $line) { $n++; if (!fputcsv($f,$line)) { show_error("Can't write line $n: $line"); } } fclose($f) or show_error("Can't close PHP://output"); $str = ob_get_contents(); ob_end_clean(); if ($download == "") { return $str; } else { echo $str; } } }
先谢谢你