8 namespace Fossology\Lib\Text;
13 const UTF8_ENCODING =
"UTF-8";
21 if ($this->isUtf8($input)) {
24 $encodings = array(
"ASCII",
"UTF-8",
"Windows-1252",
"ISO-8859-15",
"ISO-8859-1",
"GB2312");
25 $detectedCharset = mb_detect_encoding($input, $encodings,
true);
27 if (!$detectedCharset) {
28 $charsets = array(
'iso-8859-1',
'windows-1251',
'GB2312');
29 foreach ($charsets as $charset) {
30 $output = iconv($charset, self::UTF8_ENCODING .
'//TRANSLIT', $input);
36 return iconv($detectedCharset, self::UTF8_ENCODING, $input);
41 public function isUtf8($input)
43 return mb_check_encoding($input, self::UTF8_ENCODING);