Operate csv files in PHP

Source: Internet
Author: User
CSV is the most common file format, which can be easily imported into various PC tables and databases. PHP also provides functions for cvs operations. 1. generate CVS, fputcsv () format the row as CSV and write the file pointer & amp; lt ;? Ph

CSV is the most common file format, which can be easily imported into various PC tables and databases. PHP also provides functions for cvs operations.

1. generate CVS, fputcsv () format the rows as CSV and write the file pointer


  

Result:

Of course, you can generate a csv file for forced download.

2. read cvs and use the fgetcsv () file pointer to read a row and parse the CSV field

For example, I want to read the following csv file:


 $ Num fields in line $ row:
\ N "; $ row ++; for ($ c = 0; $ c <$ num; $ c ++) {// pay attention to Chinese garbled characters $ data [$ c] = iconv ("gbk", "UTF-8 // IGNORE", $ data [$ c]); echo $ data [$ c]."
\ N ";}} fclose ($ handle) ;?>

The above example is also improved in my user manual. note the Chinese encoding problem.

Extended reading: I wrote about using PHP to operate excel files:


  1. Use PHPExcel to read excel and import the database

  2. Export xls in Simple Excel

  3. Php-excel-reader reads excel content and saves it to the database

  4. Use php-excel-reader to read excel files

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.