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