PHP processing Excel file csv

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

  • 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.