This shows you the differences between two versions of the page.
Next revision Both sides next revision | |||
using_php_on_csv_files [2015/08/26 13:57] Joel Dare created |
using_php_on_csv_files [2015/08/26 14:02] Joel Dare |
||
---|---|---|---|
Line 1: | Line 1: | ||
===== Using PHP on CSV Files ===== | ===== Using PHP on CSV Files ===== | ||
- | You can use PHP to quickly get a column of data from a CSV file. A file I have has the following format. | + | You can use PHP to quickly get a column of data from a CSV file. Here's an example CSV format. |
"John", "Doe", "801-555-5555" | "John", "Doe", "801-555-5555" | ||
Line 37: | Line 37: | ||
php getcol.php | php getcol.php | ||
+ | |||
+ | The script above only uses memory for one line at a time. As a result, the number of lines it can process is almost unlimited. This is great if you're trying to use a Excel to process a file and getting the "too many rows" error message. | ||
+ | |||
+ | The fgetcsv() function is also very good at parsing quoted data correctly. |