composer update

This commit is contained in:
Manish Verma
2018-12-05 10:50:52 +05:30
parent 9eabcacfa7
commit 4addd1e9c6
3328 changed files with 156676 additions and 138988 deletions

View File

@@ -10,7 +10,7 @@ If you apply the PHP function utf8_encode() to an already-UTF8 string it will re
This class addresses this issue and provides a handy static function called \ForceUTF8\Encoding::toUTF8().
You don't need to know what the encoding of your strings is. It can be Latin1 (iso 8859-1), Windows-1252 or UTF8, or the string can have a mix of them. \ForceUTF8\Encoding::toUTF8() will convert everything to UTF8.
You don't need to know what the encoding of your strings is. It can be Latin1 (ISO 8859-1), Windows-1252 or UTF8, or the string can have a mix of them. \ForceUTF8\Encoding::toUTF8() will convert everything to UTF8.
Sometimes you have to deal with services that are unreliable in terms of encoding, possibly mixing UTF8 and Latin1 in the same string.
@@ -46,6 +46,43 @@ will output:
Fédération Camerounaise de Football
Fédération Camerounaise de Football
Fédération Camerounaise de Football
Options:
========
By default, `Encoding::fixUTF8` will use the `Encoding::WITHOUT_ICONV` flag, signalling that iconv should not be used to fix garbled UTF8 strings.
This class also provides options for iconv processing, such as `Encoding::ICONV_TRANSLIT` and `Encoding::ICONV_IGNORE` to enable these flags when the iconv class is utilized. The functionality of such flags are documented in the [PHP iconv documentation](http://php.net/manual/en/function.iconv.php).
Examples:
use \ForceUTF8\Encoding;
$str = "Fédération Camerounaise—de—Football\n"; // Uses U+2014 which is invalid ISO8859-1 but exists in Win1252
echo Encoding::fixUTF8($str); // Will break U+2014
echo Encoding::fixUTF8($str, Encoding::ICONV_IGNORE); // Will preserve U+2014
echo Encoding::fixUTF8($str, Encoding::ICONV_TRANSLIT); // Will preserve U+2014
will output:
Fédération Camerounaise?de?Football
Fédération Camerounaise—de—Football
Fédération Camerounaise—de—Football
while:
use \ForceUTF8\Encoding;
$str = "čęėįšųūž"; // Uses several characters not present in ISO8859-1 / Win1252
echo Encoding::fixUTF8($str); // Will break invalid characters
echo Encoding::fixUTF8($str, Encoding::ICONV_IGNORE); // Will remove invalid characters, keep those present in Win1252
echo Encoding::fixUTF8($str, Encoding::ICONV_TRANSLIT); // Will trasliterate invalid characters, keep those present in Win1252
will output:
????????
šž
ceeišuuž
Install via composer:
=====================

View File

@@ -1,6 +1,7 @@
{
"name": "neitanod/forceutf8",
"homepage": "https://github.com/neitanod/forceutf8",
"license": "BSD-3-Clause",
"type": "library",
"description": "PHP Class Encoding featuring popular Encoding::toUTF8() function --formerly known as forceUTF8()-- that fixes mixed encoded strings.",
"require": {

View File

@@ -183,14 +183,14 @@ class Encoding {
$text[$k] = self::toUTF8($v);
}
return $text;
}
}
if(!is_string($text)) {
return $text;
}
$max = self::strlen($text);
$buf = "";
for($i = 0; $i < $max; $i++){
$c1 = $text{$i};
@@ -258,12 +258,12 @@ class Encoding {
}
}
static function toISO8859($text) {
return self::toWin1252($text);
static function toISO8859($text, $option = self::WITHOUT_ICONV) {
return self::toWin1252($text, $option);
}
static function toLatin1($text) {
return self::toWin1252($text);
static function toLatin1($text, $option = self::WITHOUT_ICONV) {
return self::toWin1252($text, $option);
}
static function fixUTF8($text, $option = self::WITHOUT_ICONV){
@@ -274,6 +274,10 @@ class Encoding {
return $text;
}
if(!is_string($text)) {
return $text;
}
$last = "";
while($last <> $text){
$last = $text;
@@ -333,7 +337,7 @@ class Encoding {
return self::toUTF8($text);
}
protected static function utf8_decode($text, $option)
protected static function utf8_decode($text, $option = self::WITHOUT_ICONV)
{
if ($option == self::WITHOUT_ICONV || !function_exists('iconv')) {
$o = utf8_decode(