|
Posted by Rik on 08/17/07 01:12
On Fri, 17 Aug 2007 03:00:50 +0200, Rik <luiheidsgoeroe@hotmail.com> wro=
te:
>> My Second Question:
>> I can convert an array to csv pretty easily, but going the other way =
=
>> screws me up (because of quoted commas). So, my "architectural =
>> reasons" (for this and some other stuff, too) would evaporate if =
>> someone could help me write a function like this:
>>
>> function CSVtoArray($sCSV) {
>> $aryRetVal =3D array();
>> $aryRetVal =3D foo($sCSV);
>> return $aryRetVal;
>> }
>
>
> 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.
>
> You could define a stream to a variable to get fgetcsv() to work for =
> you, might be some overkill.
Hmmmz, someone posted an interesting solution:
function parseCSV($str, $delimiter =3D ',', $enclosure =3D '"', $len =3D=
0)
{
$fh =3D fopen('php://memory', 'w+');
fwrite($fh, $str);
rewind($fh);
$result =3D fgetcsv( $fh, $len, $delimiter, $enclosure );
fclose($fh);
return $result;
}
var_dump(parseCSV('"foo","bar\"",234,324,"boz"'));
-- =
Rik Wasmus
Navigation:
[Reply to this message]
|