public static function strToGBK($strText) { $encode = mb_detect_encoding($strText, array('UTF-8','GB2312','GBK')); if($encode == "UTF-8") { return @iconv('UTF-8','GB18030',$strText); } else { return $strText; } }
mb_detect_encoding:检测字符的编码
程序猿必读