Tuesday, April 14, 2009

Detect encoding charset character set Western European (Windows) or UTF-8 file in PHP

Detect encoding charset character set Western European (Windows) or UTF-8 file in PHP

$strEncode = mb_detect_encoding($contents, "UTF-8, ISO-8859-1");
if ($strEncode == 'ISO-8859-1') {
$contents = mb_convert_encoding($contents, 'UTF-8', 'CP1252');
}

$contents = mysql_real_escape_string($contents);

No comments: