php转换字符编码为utf-8

php转换字符编码为utf-8

function strToUtf8($str){
    $encode = mb_detect_encoding($str, array("ASCII",'UTF-8',"GB2312","GBK",'BIG5'));
    if($encode == 'UTF-8'){
        return $str;
    }else{
        return mb_convert_encoding($str, 'UTF-8', $encode);
    }
}

 

posted @ 2019-06-06 15:59  学知无涯  阅读(22949)  评论(1编辑  收藏  举报