Parsing a CSV file
| From: | Sharat Hegde | Date: | Wed, 03 Oct 2001 11:55:09 +0000 |
| Subject: | Parsing a CSV file | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-69753@lists.php.net to get a copy of this message | ||
Hello,
I am trying to parse a CSV (comma separated file) file to get the separate
elements. The format of each line of the file is as follows:
R001,23,"2,5"
Note that the 3rd field "2,5" is enclosed within quotes as it has commas
within the field itself. This is a standard file created when an Excel file
is saved as a CSV file. What I need after parsing this is an array with the
elements being:
Element 0 - R001
Element 1 - 23
Element 2 - 2,5
Standard split command gives 4 elements instead of 3.
I know I can do this by some brute programming, but is there an elegant way
out. Note that I am not using PHP 4.0 and hence PHP4 specific features are
not available to me as yet!
Regards,
Sharat