Index: trunk/extensions/ExternalData/ED_Utils.php |
— | — | @@ -258,10 +258,15 @@ |
259 | 259 | // doesn't get chopped off to just "b"). |
260 | 260 | $new_row = array(); |
261 | 261 | foreach ( $vars as $i => $column_name ) { |
262 | | - // Data that comes from the DB will |
263 | | - // (always?) be in ISO-8859-1 format - |
264 | | - // convert it to UTF8. |
265 | | - $new_row[$column_name] = utf8_encode( $row[$i] ); |
| 262 | + // Convert the encoding to UTF-8 |
| 263 | + // if necessary - based on code at |
| 264 | + // http://www.php.net/manual/en/function.mb-detect-encoding.php#102510 |
| 265 | + $dbField = $row[$i]; |
| 266 | + if ( mb_detect_encoding( $dbField, 'UTF-8', true ) == 'UTF-8' ) { |
| 267 | + $new_row[$column_name] = $dbField; |
| 268 | + } else { |
| 269 | + $new_row[$column_name] = utf8_encode( $dbField ); |
| 270 | + } |
266 | 271 | } |
267 | 272 | $rows[] = $new_row; |
268 | 273 | } |
— | — | @@ -293,8 +298,9 @@ |
294 | 299 | // regular expression copied from http://us.php.net/fgetcsv |
295 | 300 | $vals = preg_split( '/,(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))/', $csv_line ); |
296 | 301 | $vals2 = array(); |
297 | | - foreach ( $vals as $val ) |
| 302 | + foreach ( $vals as $val ) { |
298 | 303 | $vals2[] = trim( $val, '"' ); |
| 304 | + } |
299 | 305 | return $vals2; |
300 | 306 | } |
301 | 307 | |