24 const UTF8_ENCODING =
"UTF-8";
32 if ($this->isUtf8($input)) {
35 $encodings = array(
"ASCII",
"UTF-8",
"Windows-1252",
"ISO-8859-15",
"ISO-8859-1",
"GB2312");
36 $detectedCharset = mb_detect_encoding($input, $encodings,
true);
38 if (!$detectedCharset) {
39 $charsets = array(
'iso-8859-1',
'windows-1251',
'GB2312');
40 foreach ($charsets as $charset) {
41 $output = iconv($charset, self::UTF8_ENCODING .
'//TRANSLIT', $input);
47 return iconv($detectedCharset, self::UTF8_ENCODING, $input);
52 public function isUtf8($input)
54 return mb_check_encoding($input, self::UTF8_ENCODING);