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

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]


Удаленная работа для программистов  •  Как заработать на 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

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