|
Posted by Michael Fesser on 08/17/07 16:13
..oO(Rik)
>On Fri, 17 Aug 2007 03:00:50 +0200, Rik <luiheidsgoeroe@hotmail.com> wrote:
>>
>> Well, there's one in the making or something:
>> <http://nl3.php.net/manual/en/function.str-getcsv.php>, it's not in my
>> PHP though.
It's already in CVS (since 8 months or so), but obviously not in the
current branches. One could use function_exists() to check for it and
implement a custom str-getcsv() function if necessary, using one of the
ways described below.
>> You could define a stream to a variable to get fgetcsv() to work for
>> you, might be some overkill.
The manual for stream_wrapper_register() contains a little example class
"VariableStream" to access global variables. This could be useful here
(should even work with PHP 4).
>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"'));
Clever. Ugly, but clever. ;)
Micha
Navigation:
[Reply to this message]
|