Example <?php exampleLine = "R001,23,\"2,5\"";
preg_match_all ("/(\"[^\"]+\"|[^,]+)/", exampleLine, $matches); for ($i=0; $i< count($matches[0]); $i++) { echo "matched: ".$matches[0][$i]."<br>"; } ?> Please note, empty elements will not be handled btw Any Australian employers want a programmer for awhile? ----- Original Message ----- From: Sharat Hegde <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, October 03, 2001 9:55 PM Subject: [PHP] Parsing a CSV file > 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]