28 private static $CP1252Map = array(
29 "\xc2\x80" =>
"\xe2\x82\xac",
30 "\xc2\x82" =>
"\xe2\x80\x9a",
31 "\xc2\x83" =>
"\xc6\x92",
32 "\xc2\x84" =>
"\xe2\x80\x9e",
33 "\xc2\x85" =>
"\xe2\x80\xa6",
34 "\xc2\x86" =>
"\xe2\x80\xa0",
35 "\xc2\x87" =>
"\xe2\x80\xa1",
36 "\xc2\x88" =>
"\xcb\x86",
37 "\xc2\x89" =>
"\xe2\x80\xb0",
38 "\xc2\x8a" =>
"\xc5\xa0",
39 "\xc2\x8b" =>
"\xe2\x80\xb9",
40 "\xc2\x8c" =>
"\xc5\x92",
41 "\xc2\x8e" =>
"\xc5\xbd",
42 "\xc2\x91" =>
"\xe2\x80\x98",
43 "\xc2\x92" =>
"\xe2\x80\x99",
44 "\xc2\x93" =>
"\xe2\x80\x9c",
45 "\xc2\x94" =>
"\xe2\x80\x9d",
46 "\xc2\x95" =>
"\xe2\x80\xa2",
47 "\xc2\x96" =>
"\xe2\x80\x93",
48 "\xc2\x97" =>
"\xe2\x80\x94",
50 "\xc2\x98" =>
"\xcb\x9c",
51 "\xc2\x99" =>
"\xe2\x84\xa2",
52 "\xc2\x9a" =>
"\xc5\xa1",
53 "\xc2\x9b" =>
"\xe2\x80\xba",
54 "\xc2\x9c" =>
"\xc5\x93",
55 "\xc2\x9e" =>
"\xc5\xbe",
56 "\xc2\x9f" =>
"\xc5\xb8"
64 public static function isUtf8($string) {
65 if ($string === mb_convert_encoding(mb_convert_encoding($string,
"UTF-32",
"UTF-8"),
"UTF-8",
"UTF-32")) {
79 return utf8_decode(strtr($string, array_flip(self::$CP1252Map)));
88 return strtr(utf8_encode($string), self::$CP1252Map);
99 if(is_array($input)) {
101 foreach($input as $k => $v) {
102 $key = ($encodeKeys) ? self::convertIsoToCp1252Utf8($k) : $k;
103 $result[$key] = self::utf8EncodeMix($v, $encodeKeys);
107 if (!is_int($input) && !is_float($input) && !is_bool($input) && !self::isUtf8($input)) {
108 $result = self::convertIsoToCp1252Utf8($input);
static convertIsoToCp1252Utf8($string)
Encodes ISO strings to mixed CP1252 UTF-8.
Input/Output related interfaces and classes.
EncodingUtil provides helper functions for working with different encodings mainly UTF-8...
static isUtf8($string)
Returns true if the given string is valid UTF-8 and false otherwise.
static utf8EncodeMix($input, $encodeKeys=false)
Encodes an ISO-8859-1 mixed variable to UTF-8 (PHP 4, PHP 5 compat)
static convertCp1252Utf8ToIso($string)
Decodes mixed CP1252 UTF-8 strings to ISO.