Re: File-CSV patch

From: Date: Thu, 01 Aug 2002 09:42:06 +0000
Subject: Re: File-CSV patch
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-8112@lists.php.net to get a copy of this message
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'];

« previous php.pear.dev (#8112) next »