[dev] Fwd: [PEAR-DEV] Re: File-CSV patch
Chuck Hagenbuch
chuck@horde.org
Thu, 1 Aug 2002 08:53:04 -0400
FYI
----- Forwarded message from cox@idecnet.com -----
Date: Thu, 01 Aug 2002 11:42:06 +0200
From: "Tomas V.V.Cox" <cox@idecnet.com>
Reply-To: "Tomas V.V.Cox" <cox@idecnet.com>
Subject: [PEAR-DEV] Re: File-CSV patch
To: pear-dev@lists.php.net, Wolfram Kriesing <lists@kriesing.de>
Wolfram Kriesing wrote:
>
> attached please find a patch, which fixes the following problems that
> i had using the File_CSV::write-method:
> - use of associative arrays
Ok
> - escape the <quote> character (by doubling it)
Well, time ago someone wrote that to escape <quote>'s should be used ^
or \ according to a not very official standar in OpenText (what I
remember quickly from that post). We need to add a new conf param
$conf['escape_quote_char'] instead of doubling it IMHO.
> - replace the <crlf> character by a space,
> so it doesnt screw up the CSV file
Why it screw up the CSV file? At least the class is enough smart for
reading multilined entries, don't others?
> i hope the patch is fine, it works well for me
Sorry if I'm too slow these days. Next week I'll hopefully be on
hollidays again and will attend all my Pear TODO hash :-)
Tomas V.V.Cox
> --
> Wolfram
>
> ... translating template engine ....
> http://sf.net/projects/simpletpl
>
> ... authentication system ....
> http://sf.net/projects/auth
>
> @@ -326,13 +326,26 @@
> return true;
> }
> $write = '';
> - for ($i = 0; $i < count($fields); $i++) {
> - if (!is_numeric($fields[$i]) && $conf['quote']) {
> - $write .= $conf['quote'] . $fields[$i] . $conf['quote'];
> +
> + $i = 0;
> + if( is_array($fields) && sizeof($fields) )
> + foreach( $fields as $aField ) // this way this class will
> also work with associative arrays
> + {
> + $i++; // count the
> number of elements
> +
> + // replace the quote char by two of them
> + $aField = str_replace( $conf['quote'] ,
> $conf['quote'].$conf['quote'] , $aField );
> + // i dont know what else to replace it with? any better
> ideas?
> + $aField = str_replace( $conf['crlf'] , ' ' , $aField );
> +
> + if (!is_numeric($aField) && $conf['quote']) {
> + $write .= $conf['quote'] . $aField . $conf['quote'];
> } else {
> - $write .= $fields[$i];
> + $write .= $aField;
> }
> - if ($i < (count($fields) - 1)) {
> +
> + // what is this supposed to do? should it not use modulo,
> if at all?
> + if ($i < (count($fields) )) {
> $write .= $conf['sep'];
> } else {
> $write .= $conf['crlf'];
--
PEAR Development Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
----- End forwarded message -----
-chuck
--
Charles Hagenbuch, <chuck@horde.org>
"After a few minutes the most aromatic and nice smelling Italian coffee
will come out of the exhaustpipe." - Our stove-top espresso pot