You are here: Re: Scrubbing MySQL Values and CSVtoArray() « PHP Programming Language « IT news, forums, messages
Re: Scrubbing MySQL Values and CSVtoArray()

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация