Richard Lynch wrote:
On Fri, August 19, 2005 3:47 pm, Jasper Bryant-Greene wrote:
For CSV, it's as simple as explode() the data by "\n" (perhaps strip
out
any "\r" before you start) and then explode() by ",". Depending on the
software they're using, you might also need to remove any delimiters
on
each field of data, such as quote marks (").

No, it's not that simple, as embedded commas can be inside of quotes,
and then quote quote is used for quotes inside of quotes.

Which is why PHP has a function for reading CSV files.
http://php.net/fgetcsv I believe.

Very good point. It can still be solved relatively simply with PHP's string and/or regex functions though, although that would be rather pointless as a function already exists. Thanks for pointing out the function, I hadn't seen it before.

If other file formats are possible as well as CSV, you might like to
look at the PEAR "File Formats" packages[1].

Now TAB delimited is generally easier than CSV as it IS as simple as
reading a line and explode() on "\t"

Unless of course the field is delimited with quotes and contains an embedded tab character? Just a guess, I haven't had any reason to use tab-delimited files before.

Jasper

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to