Changeset 12974
- Timestamp:
- 11/13/08 14:09:32 (5 years ago)
- Files:
-
- plugins/sfCsvPlugin/lib/sfCsvReader.class.php (modified) (4 diffs)
- plugins/sfCsvPlugin/lib/sfCsvWriter.class.php (modified) (1 diff)
- plugins/sfCsvPlugin/package.xml (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfCsvPlugin/lib/sfCsvReader.class.php
r12970 r12974 26 26 * } 27 27 * $csv->close(); 28 * 29 * 30 * --- CHARSET --- 31 * $to = 'ISO-8859-1'; 32 * $from = 'UTF-8'; 33 * $csv->setCharset($to); 34 * $csv->setCharset($to, $from); 28 35 */ 29 36 class sfCsvReader … … 40 47 $length, 41 48 $delimiter, 42 $enclosure; 49 $enclosure, 50 $to, 51 $from; 43 52 44 53 /** … … 181 190 foreach ($this->header['selected'] as $name) 182 191 { 183 $res[$name] = $line[$this->header['map'][$name]]; 192 if ($this->to !== null) 193 { 194 $res[$name] = $this->encode($line[$this->header['map'][$name]], $this->to, $this->from); 195 } 196 else 197 { 198 $res[$name] = $line[$this->header['map'][$name]]; 199 } 184 200 } 185 201 return $res; … … 196 212 } 197 213 214 private function encode($str, $to, $from = null) 215 { 216 if ($from === null) 217 { 218 $from = mb_detect_encoding($str); 219 } 220 221 if (function_exists('iconv')) 222 { 223 return iconv($from, $to, $str); 224 } 225 else 226 { 227 return mb_convert_encoding($str, $to, $from); 228 } 229 } 230 231 public function setCharset($to, $from = null) 232 { 233 $this->to = $to; 234 $this->from = $from; 235 } 236 198 237 function __destruct() 199 238 { plugins/sfCsvPlugin/lib/sfCsvWriter.class.php
r12970 r12974 103 103 } 104 104 105 return mb_convert_encoding($str, $to, $from); 105 if (function_exists('iconv')) 106 { 107 return iconv($from, $to, $str); 108 } 109 else 110 { 111 return mb_convert_encoding($str, $to, $from); 112 } 106 113 } 107 114 plugins/sfCsvPlugin/package.xml
r12970 r12974 11 11 <active>yes</active> 12 12 </lead> 13 <date>2008-1 0-10</date>14 <time>1 0:37:33</time>13 <date>2008-11-13</date> 14 <time>14:05:00</time> 15 15 <version> 16 <release>0.1. 0</release>17 <api>0.1. 0</api>16 <release>0.1.1</release> 17 <api>0.1.1</api> 18 18 </version> 19 19 <stability> … … 50 50 </dependencies> 51 51 <phprelease /> 52 <changelog /> 52 <changelog> 53 <release> 54 <version> 55 <release>0.1.1</release> 56 <api>0.1.1</api> 57 </version> 58 <stability> 59 <release>beta</release> 60 <api>beta</api> 61 </stability> 62 <license uri="http://www.symfony-project.com/license">MIT license</license> 63 <notes> 64 * Roman ZajÄ…c added iconv / charset support into `sfCsvReader` class and I ported that iconv improvement to `sfCsvWriter` class `encode` method. 65 </notes> 66 </release> 67 </changelog> 53 68 </package>