PHP——字符串统一转码为GBK,自动判断是否UTF8并转码

    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:检测字符的编码

程序猿必读