Php processes Excel file csv

Source: Internet
Author: User
: 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.