字符串转换成UTF-8编码

function strToUtf8($vector) {
	$from_chr = mb_detect_encoding ( $vector, array (
			'UTF-8',
			'ASCII',
			'EUC-CN',
			'CP936',
			'BIG-5',
			'GB2312',
			'GBK' 
	) );
	if ($from_chr != "UTF-8") {
		$vector = mb_convert_encoding ( $vector, 'UTF-8', array (
				'UTF-8',
				'ASCII',
				'EUC-CN',
				'CP936',
				'BIG-5',
				'GB2312',
				'GBK' 
		) );
	}
	return $vector;
}

猜你喜欢

转载自panyongzheng.iteye.com/blog/1855447