php怎麼把字元編碼轉utf8

2020-07-16 10:06:27

php把字元編碼轉utf8的方法:

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);
    }
}

//mb_convert_encoding('要轉編碼的字串','目標編碼','原編碼')
//mb_detect_encoding('字串'):
mb_convert_encoding($str,'utf-8',mb_detect_encoding($str))

以上就是php怎麼把字元編碼轉utf8的詳細內容,更多請關注TW511.COM其它相關文章!