This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
using_php_on_csv_files [2015/08/26 13:57] Joel Dare created |
using_php_on_csv_files [2020/06/01 22:53] (current) |
||
---|---|---|---|
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. | ||
+ | |||
+ | <html> | ||
+ | <a id="csv_link" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SNV2TUB7Q3PKN"> | ||
+ | <img id="csv_submission" src="https://dl.dropboxusercontent.com/u/58852318/ads/csv_submission/csv_subscription_a.png"> | ||
+ | </a> | ||
+ | </html> |