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:
Use PHPExcel to read excel and import the database
Export xls in Simple Excel
Php-excel-reader reads excel content and saves it to the database
Use php-excel-reader to read excel files