#55: Reading a Comma-Separated File

One common programming task is to transform data from Excel spreadsheets into some useful form, such as HTML or rows in a MySQL table. If we all had to work in Excel (XLS) format, then this would be a real problem. Fortunately, in both Excel and OpenOffice.org, you can export an Excel file into CSV (comma-separated value) format. CSV format is a fancy way to say that it's a text file with one line per data row, with commas between the fields in the row. It looks like this:

"Airport","City","Activity"
"LON","London","Museums"
"PAR","Paris","Dining"
"SLC","Salt Lake City","Skiing"

Although you may think that this is just a matter of grabbing lines and splitting them using a comma as a delimiter, you have to worry ...

Get Wicked Cool PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.