PHP problem character set

punkstist

New Member
I have a problem where users upload zipped text files. After I extract text contents I import them in mysql database. But later when I display the text in browser some characters are garbled. I tried to encode them but I am unable to detect the encoding of the text files with PHP and convert to UTF-8 with iconv or mbstring.Mysql database charset is UTF-8.\[code\]header('Content-type: text/html; charset=utf-8');\[/code\]is added.Tried with iconv('UTF-8', 'UTF-8//IGNORE', $text_file_contents)But it simply removes the garbled chars: ? which should be either ' or " when I checked manually with Firefox browser. Firefox showed that is ISO-8859-1 but I can not check for every article they send (articles may be in different character set).How to convert this characters to UTF-8 ?EDIT: This is a modified function I found on http://php.net/manual/en/function.mb-detect-encoding.phporiganlly written by prgss at bk dot ru .function myutf8_detect_encoding($string, $default = 'UTF-8', $encode = 0, $encode_to = 'UTF-8') { static $list = array('UTF-8', 'ISO-8859-1', 'ASCII', 'windows-1250', 'windows-1251', 'latin1', 'windows-1252', 'windows-1253', 'windows-1254', 'windows-1255', 'windows-1256', 'windows-1257', 'windows-1258', 'ISO-8859-2', 'ISO-8859-3', 'GBK', 'GB2312', 'GB18030', 'MACROMAN', 'ISO-8859-4', 'ISO-8859-5', 'ISO-8859-6', 'ISO-8859-7', 'ISO-8859-8', 'ISO-8859-9', 'ISO-8859-10', 'ISO-8859-11', 'ISO-8859-12', 'ISO-8859-13', 'ISO-8859-14', 'ISO-8859-15', 'ISO-8859-16'); foreach ($list as $item) { $sample = iconv($item, $item, $string); if (md5($sample) == md5($string)) { if ($encode == 1) return iconv($item, $encode_to, $string); else return $item; } } if ($encode == 1) return iconv($encode_to, $encode_to . '//IGNORE', $string); else return $default;} and in my code I use:\[code\]myutf8_detect_encoding(trim($description), 'UTF-8', 1)\[/code\]but it still returns garbled characters of this text
 
Back
Top