Values with commas

While figuring out our import / export data exchange module, we ran across this problem in inc/classes/BxDolPFM.php, starting at line 1227.  Looks like it needs to quote values before joining, not after, in case values contain commas.

 

$sValuesAlter = implode( ', ', $aValuesAlter );

$sValuesAlter = str_replace( '\\', '\\\\', $sValuesAlter );

$sValuesAlter = str_replace( '\'', '\\\'', $sValuesAlter );

It should probably be done the same way it's done above, by looping  through:

foreach( $aValuesAlter as $iKey => $sValue ){ //add slashes to every value

$sValue = str_replace( '\\', '\\\\', $sValue );

$sValue = str_replace( '\'', '\\\'', $sValue );

$aValuesAlter[$iKey] = $sValue;

}

Of course, there's probably a better way, that wouldn't need to duplicated lines of code.  Or maybe with array_walk or something like that (in perl it would be map).  But imploding an array with commas, then operating on it, is going to be a problem.  Imploding after it's been escaped would be better.
Tac
Quote · 1 Dec 2010
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.