php 字符安全转码为UTF-8 的函数,转换前做判断

不废话,直接上代码:


function safeEncoding($string,$outEncoding = 'UTF-8')
{
	$encoding = "UTF-8";
	$encoding = mb_detect_encoding($string, array("UTF-8", "GB2312", "GBK", "EUC-JP", "HZ"));
	if(strtoupper($encoding) == strtoupper($outEncoding))
		return $string;
	else
		return iconv($encoding,$outEncoding,$string);
}



你可能感兴趣的:(php)