CSV file format
"数据1","数据2","数据3""数据4","数据5","数据6"
? To save a two-dimensional array as a CSV file Fputcsv ()
$csv_arr = ( array(1,2,3,4), array(5,6,7,8), array(12,34,56,78));$fh = fopen('test.csv','w'ordie("can't open file test.csv");foreach($csv_arras$csv_arr_line){ if(fputcsv($fh,$csv_arr_linefalse){ die(‘can not write test.csv !’); }}fclose($fhordie("can not close test.csv !");
Want to output data in CSV format php://output
$csv_arr = ( array(1,2,3,4), array(5,6,7,8), array(12,34,56,78));$fh = fopen('php://output','w');foreach($csv_arras$csv_arr_line){ if(fputcsv($fh,$csv_arr_linefalse){ die(‘can not write csv line !’); }}fclose($fh);
? You want to save data in CSV format to the string OB buffer
$csv_arr = ( array(1,2,3,4), array(5,6,7,8), array(12,34,56,78));ob_start();$fh = fopen('test.csv','w'ordie("can't open php://output");foreach($csv_arras$csv_arr_line){ if(fputcsv($fh,$csv_arr_linefalse){ die(‘can not write csv line !’); }}fclose($fhordie("can not close php://output !");$output = ob_get_contents();ob_end_clean();
Copyright Notice: Knowledge is taken to the people, to the people! Welcome reprint, Reprint please attach this article link, not regularly updated articles!
The above describes the PHP processing Excel file CSV, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.