PHP Cookbook: Parsing Comma-Separated Data
Problem
You have data in comma-separated values (CSV) format—for example, a file exported from Excel or a database—and you want to extract the records and fields into a format you can manipulate in PHP.
Solution
If the CSV data is in a file (or available via a URL), open the file with fopen( ) and read in the data with fgetcsv( ) . Example 1-31 prints out CSV data in an HTML table. (more…)