![](http://m.sbmmt.com/img/upload/article/000/000/051/5ee0893c49c1b765.jpg)
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中文网其它相关文章!
声明:本文原创发布php中文网,转载请注明出处,感谢您的尊重!如有疑问,请联系admin@php.cn处理
上一篇:php中日期怎么转换为时间戳 下一篇:php中字符怎么转编码