comma delineated files

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Say I have an file whose contents are as follows:


How would I go about turning that file into an array, as follows?:

$file_contents = array('"test"','"com,ma"','"food"');

Doing explode(',',$file_contents) wouldn't be sufficient because the
resultant array would have four entries - not three - and would instead
read like this:

$file_contents = array('"test"','"com','ma"','"food"');

I could probably iterate through each character within the array, but
that, it seems to me, would be inefficient.  Plus, it'd require more
code that'd be nice to avoid.

So, anyway, any ideas?

Re: comma delineated files

try with preg_match_all() ( )

Re: comma delineated files

I should, perhaps, also mention that strings aren't the only things
that can be between the commas.  Another valid file is as follows:


Given this, the regular expression is, at the very least, not going to
be particuraly easy.   Before making the original post, I was unable to
come up with a sufficient one for preg_split.

As such, if regular expressions are the key, I could still use some

Re: comma delineated files

yawnmoth said the following on 02/11/2005 01:52:
Quoted text here. Click to load it

A shortcut might be .


Site Timeline