php怎么把字符编码转utf8-PHP问题

资源魔 15 0

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教程 php故障解决 php使用问题

抱歉,评论功能暂时关闭!