← All changes
|
vendor/neitanod/forceutf8/src/ForceUTF8/Encoding.php
+17
-21
4.0.8
→
3.0.10
View file →
| @@ -182,23 +182,23 @@ | ||
| 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 | - $c1 = $text[$i]; | |
| 196 | + $c1 = $text{$i}; | |
| 197 | 197 | if($c1>="\xc0"){ //Should be converted to UTF8, if it's not UTF8 already |
| 198 | - $c2 = $i+1 >= $max? "\x00" : $text[$i+1]; | |
| 199 | - $c3 = $i+2 >= $max? "\x00" : $text[$i+2]; | |
| 200 | - $c4 = $i+3 >= $max? "\x00" : $text[$i+3]; | |
| 198 | + $c2 = $i+1 >= $max? "\x00" : $text{$i+1}; | |
| 199 | + $c3 = $i+2 >= $max? "\x00" : $text{$i+2}; | |
| 200 | + $c4 = $i+3 >= $max? "\x00" : $text{$i+3}; | |
| 201 | 201 | if($c1 >= "\xc0" & $c1 <= "\xdf"){ //looks like 2 bytes UTF8 |
| 202 | 202 | if($c2 >= "\x80" && $c2 <= "\xbf"){ //yeah, almost sure it's UTF8 already |
| 203 | 203 | $buf .= $c1 . $c2; |
| 204 | 204 | $i++; |
| @@ -229,9 +229,9 @@ | ||
| 229 | 229 | $cc1 = (chr(ord($c1) / 64) | "\xc0"); |
| 230 | 230 | $cc2 = (($c1 & "\x3f") | "\x80"); |
| 231 | 231 | $buf .= $cc1 . $cc2; |
| 232 | 232 | } |
| 233 | - } elseif(($c1 & "\xc0") === "\x80"){ // needs conversion | |
| 233 | + } elseif(($c1 & "\xc0") == "\x80"){ // needs conversion | |
| 234 | 234 | if(isset(self::$win1252ToUtf8[ord($c1)])) { //found in Windows-1252 special cases |
| 235 | 235 | $buf .= self::$win1252ToUtf8[ord($c1)]; |
| 236 | 236 | } else { |
| 237 | 237 | $cc1 = (chr(ord($c1) / 64) | "\xc0"); |
| @@ -257,14 +257,14 @@ | ||
| 257 | 257 | return $text; |
| 258 | 258 | } |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - static function toISO8859($text, $option = self::WITHOUT_ICONV) { | |
| 262 | - return self::toWin1252($text, $option); | |
| 261 | + static function toISO8859($text) { | |
| 262 | + return self::toWin1252($text); | |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | - static function toLatin1($text, $option = self::WITHOUT_ICONV) { | |
| 266 | - return self::toWin1252($text, $option); | |
| 265 | + static function toLatin1($text) { | |
| 266 | + return self::toWin1252($text); | |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | static function fixUTF8($text, $option = self::WITHOUT_ICONV){ |
| 270 | 270 | if(is_array($text)) { |
| @@ -273,12 +273,8 @@ | ||
| 273 | 273 | } |
| 274 | 274 | return $text; |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | - if(!is_string($text)) { | |
| 278 | - return $text; | |
| 279 | - } | |
| 280 | - | |
| 281 | 277 | $last = ""; |
| 282 | 278 | while($last <> $text){ |
| 283 | 279 | $last = $text; |
| 284 | 280 | $text = self::toUTF8(static::utf8_decode($text, $option)); |
| @@ -295,9 +291,9 @@ | ||
| 295 | 291 | return str_replace(array_keys(self::$brokenUtf8ToUtf8), array_values(self::$brokenUtf8ToUtf8), $text); |
| 296 | 292 | } |
| 297 | 293 | |
| 298 | 294 | static function removeBOM($str=""){ |
| 299 | - if(substr($str, 0,3) === pack("CCC",0xef,0xbb,0xbf)) { | |
| 295 | + if(substr($str, 0,3) == pack("CCC",0xef,0xbb,0xbf)) { | |
| 300 | 296 | $str=substr($str, 3); |
| 301 | 297 | } |
| 302 | 298 | return $str; |
| 303 | 299 | } |
| @@ -332,13 +328,13 @@ | ||
| 332 | 328 | |
| 333 | 329 | public static function encode($encodingLabel, $text) |
| 334 | 330 | { |
| 335 | 331 | $encodingLabel = self::normalizeEncoding($encodingLabel); |
| 336 | - if($encodingLabel === 'ISO-8859-1') return self::toLatin1($text); | |
| 332 | + if($encodingLabel == 'ISO-8859-1') return self::toLatin1($text); | |
| 337 | 333 | return self::toUTF8($text); |
| 338 | 334 | } |
| 339 | 335 | |
| 340 | - protected static function utf8_decode($text, $option = self::WITHOUT_ICONV) | |
| 336 | + protected static function utf8_decode($text, $option) | |
| 341 | 337 | { |
| 342 | 338 | if ($option == self::WITHOUT_ICONV || !function_exists('iconv')) { |
| 343 | 339 | $o = utf8_decode( |
| 344 | 340 | str_replace(array_keys(self::$utf8ToWin1252), array_values(self::$utf8ToWin1252), self::toUTF8($text)) |
| @@ -343,9 +339,9 @@ | ||
| 343 | 339 | $o = utf8_decode( |
| 344 | 340 | str_replace(array_keys(self::$utf8ToWin1252), array_values(self::$utf8ToWin1252), self::toUTF8($text)) |
| 345 | 341 | ); |
| 346 | 342 | } else { |
| 347 | - $o = iconv("UTF-8", "Windows-1252" . ($option === self::ICONV_TRANSLIT ? '//TRANSLIT' : ($option === self::ICONV_IGNORE ? '//IGNORE' : '')), $text); | |
| 343 | + $o = iconv("UTF-8", "Windows-1252" . ($option == self::ICONV_TRANSLIT ? '//TRANSLIT' : ($option == self::ICONV_IGNORE ? '//IGNORE' : '')), $text); | |
| 348 | 344 | } |
| 349 | 345 | return $o; |
| 350 | 346 | } |
| 351 | 347 | } |