Skip to content

Commit 30980a8

Browse files
committed
Examples in documentation
1 parent fa82e98 commit 30980a8

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

README.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ If you apply the PHP function utf8_encode() to an already-UTF8 string it will re
1010

1111
This class addresses this issue and provides a handy static function called \ForceUTF8\Encoding::toUTF8().
1212

13-
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.
13+
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.
1414

1515
Sometimes you have to deal with services that are unreliable in terms of encoding, possibly mixing UTF8 and Latin1 in the same string.
1616

@@ -57,17 +57,33 @@ Examples:
5757

5858
use \ForceUTF8\Encoding;
5959

60-
$str = "Fédération Camerounaise—de—Football\n"; // Uses U+2014 which is invalid
61-
echo Encoding::fixUTF8($str); // Breaks invalid char (U+2014)
62-
echo Encoding::fixUTF8($str, Encoding::ICONV_TRANSLIT);
63-
echo Encoding::fixUTF8($str, Encoding::ICONV_TRANSLIT);
64-
60+
$str = "Fédération Camerounaise—de—Football\n"; // Uses U+2014 which is invalid ISO8859-1 but exists in Win1252
61+
echo Encoding::fixUTF8($str); // Will break U+2014
62+
echo Encoding::fixUTF8($str, Encoding::ICONV_IGNORE); // Will preserve U+2014
63+
echo Encoding::fixUTF8($str, Encoding::ICONV_TRANSLIT); // Will preserve U+2014
64+
6565
will output:
6666

6767
Fédération Camerounaise?de?Football
6868
Fédération Camerounaise—de—Football
6969
Fédération Camerounaise—de—Football
7070

71+
while:
72+
73+
use \ForceUTF8\Encoding;
74+
75+
$str = "čęėįšųūž"; // Uses several characters not present in ISO8859-1 / Win1252
76+
echo Encoding::fixUTF8($str); // Will break invalid characters
77+
echo Encoding::fixUTF8($str, Encoding::ICONV_IGNORE); // Will remove invalid characters, keep those present in Win1252
78+
echo Encoding::fixUTF8($str, Encoding::ICONV_TRANSLIT); // Will trasliterate invalid characters, keep those present in Win1252
79+
80+
will output:
81+
82+
????????
83+
šž
84+
ceeišuuž
85+
86+
7187
Install via composer:
7288
=====================
7389
Edit your composer.json file to include the following:

0 commit comments

Comments
 (0)