19 $charsetFrom = static::resolveAlias($charsetFrom);
20 $charsetTo = static::resolveAlias($charsetTo);
22 if ((
string)$charsetFrom ==
'' || (
string)$charsetTo ==
'')
28 if (strcasecmp($charsetFrom, $charsetTo) == 0)
37 if (@mb_encoding_aliases($charsetFrom) ===
false || @mb_encoding_aliases($charsetTo) ===
false)
74 protected static function convert($data, $charsetFrom, $charsetTo)
76 if (is_array($data) || $data instanceof \SplFixedArray)
79 if ($data instanceof \SplFixedArray)
81 $result = clone $data;
87 foreach ($data as $key => $value)
92 $result[$newKey] = $newValue;
96 elseif (is_string($data))
102 return static::convertByMbstring($data, $charsetFrom, $charsetTo);
229 if (strtoupper($charsetFrom) ==
"UTF-16")
231 $ch = substr($data, 0, 1);
232 if ($ch ==
"\xFF" && substr($data, 1, 1) ==
"\xFE")
235 $res = mb_convert_encoding(substr($data, 2), $charsetTo,
"UTF-16LE");
237 elseif ($ch ==
"\xFE" && substr($data, 1, 1) ==
"\xFF")
240 $res = mb_convert_encoding(substr($data, 2), $charsetTo, $charsetFrom);
245 $res = mb_convert_encoding($data, $charsetTo,
"UTF-16LE");
250 $res = mb_convert_encoding($data, $charsetTo, $charsetFrom);