← All changes
|
vendor/neitanod/forceutf8/src/ForceUTF8/Encoding.php
+13
-9
3.0.8
→
3.2.1
View file →
| @@ -182,16 +182,16 @@ | ||
| 182 | 182 | { |
| 183 | 183 | $text[$k] = self::toUTF8($v); |
| 184 | 184 | } |
| 185 | 185 | return $text; |
| 186 | - } | |
| 187 | - | |
| 186 | + } | |
| 187 | + | |
| 188 | 188 | if(!is_string($text)) { |
| 189 | 189 | return $text; |
| 190 | 190 | } |
| 191 | - | |
| 191 | + | |
| 192 | 192 | $max = self::strlen($text); |
| 193 | - | |
| 193 | + | |
| 194 | 194 | $buf = ""; |
| 195 | 195 | for($i = 0; $i < $max; $i++){ |
| 196 | 196 | $c1 = $text{$i}; |
| 197 | 197 | if($c1>="\xc0"){ //Should be converted to UTF8, if it's not UTF8 already |
| @@ -257,14 +257,14 @@ | ||
| 257 | 257 | return $text; |
| 258 | 258 | } |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - static function toISO8859($text) { | |
| 262 | - return self::toWin1252($text); | |
| 261 | + static function toISO8859($text, $option = self::WITHOUT_ICONV) { | |
| 262 | + return self::toWin1252($text, $option); | |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | - static function toLatin1($text) { | |
| 266 | - return self::toWin1252($text); | |
| 265 | + static function toLatin1($text, $option = self::WITHOUT_ICONV) { | |
| 266 | + return self::toWin1252($text, $option); | |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | static function fixUTF8($text, $option = self::WITHOUT_ICONV){ |
| 270 | 270 | if(is_array($text)) { |
| @@ -273,8 +273,12 @@ | ||
| 273 | 273 | } |
| 274 | 274 | return $text; |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | + if(!is_string($text)) { | |
| 278 | + return $text; | |
| 279 | + } | |
| 280 | + | |
| 277 | 281 | $last = ""; |
| 278 | 282 | while($last <> $text){ |
| 279 | 283 | $last = $text; |
| 280 | 284 | $text = self::toUTF8(static::utf8_decode($text, $option)); |
| @@ -332,9 +336,9 @@ | ||
| 332 | 336 | if($encodingLabel == 'ISO-8859-1') return self::toLatin1($text); |
| 333 | 337 | return self::toUTF8($text); |
| 334 | 338 | } |
| 335 | 339 | |
| 336 | - protected static function utf8_decode($text, $option) | |
| 340 | + protected static function utf8_decode($text, $option = self::WITHOUT_ICONV) | |
| 337 | 341 | { |
| 338 | 342 | if ($option == self::WITHOUT_ICONV || !function_exists('iconv')) { |
| 339 | 343 | $o = utf8_decode( |
| 340 | 344 | str_replace(array_keys(self::$utf8ToWin1252), array_values(self::$utf8ToWin1252), self::toUTF8($text)) |