|
Posted by Sanders Kaufman on 08/17/07 02:06
Rik wrote:
> Hmmmz, someone posted an interesting solution:
>
> function parseCSV($str, $delimiter = ',', $enclosure = '"', $len = 0)
> {
> $fh = fopen('php://memory', 'w+');
> fwrite($fh, $str);
> rewind($fh);
> $result = fgetcsv( $fh, $len, $delimiter, $enclosure );
> fclose($fh);
> return $result;
> }
> var_dump(parseCSV('"foo","bar\"",234,324,"boz"'));
Oh, I get it! PHP can parse a CSV *file*, but not a CSV *string*. So,
to parse the string, he just created a file in memory, and parsed that.
That's cool. I'll bet there are other cool ways to make use of that
technique.
[Back to original message]
|