: This article mainly introduces how to process Excel file csv in php. For more information about PHP tutorials, see. Csv file format
"Data 1", "Data 2", "Data 3" "data 4", "Data 5", "Data 6"
? 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_line) === false){ die(‘can not write test.csv !’); }}fclose($fh) ordie("can not close test.csv !");
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_line) === false){ die(‘can not write csv line !’); }}fclose($fh);
? Want to save csv data 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_line) === false){ die(‘can not write csv line !’); }}fclose($fh) ordie("can not close php://output !");$output = ob_get_contents();ob_end_clean();
Copyright disclaimer: knowledge is used by the people! You are welcome to repost this article. For more information, see the link at the beginning!
The above section describes how to process the Excel file csv in php, including some content. if you are interested in the PHP Tutorial, please help.