detect if function iconv exists before trying to use it while detecting charset

This commit is contained in:
Klaus Leithoff 2010-10-11 12:54:17 +00:00
parent 862e07d9a3
commit e8349f3daa

View File

@ -3133,11 +3133,13 @@
*/ */
static function detect_encoding($string) { static function detect_encoding($string) {
static $list = array('utf-8', 'iso-8859-1', 'windows-1251'); // list may be extended static $list = array('utf-8', 'iso-8859-1', 'windows-1251'); // list may be extended
if (function_exists('iconv'))
foreach ($list as $item) { {
$sample = iconv($item, $item, $string); foreach ($list as $item) {
if (md5($sample) == md5($string)) $sample = iconv($item, $item, $string);
return $item; if (md5($sample) == md5($string))
return $item;
}
} }
return false; // we may choose to return iso-8859-1 as default at some point return false; // we may choose to return iso-8859-1 as default at some point
} }