File-CSV patch

From: Date: Mon, 29 Jul 2002 16:42:08 +0000
Subject: File-CSV patch
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-8072@lists.php.net to get a copy of this message
attached please find a patch, which fixes the following problems that i had using the File_CSV::write-method: - use of associative arrays - escape the <quote> character (by doubling it) - replace the <crlf> character by a space, so it doesnt screw up the CSV file i hope the patch is fine, it works well for me -- 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 (#8072) next »