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教程》
以上是php怎么把字符编码转utf8的详细内容。更多信息请关注PHP中文网其他相关文章!