php如何把字符串转为utf-8

藏色散人
藏色散人原创
2023-03-05 06:02:025625浏览

php把字符串转为utf-8的方法:首先找出字符串本身的编码;然后通过“mb_convert_encoding($str, 'UTF-8', $current_encode);”方法把字符串转为utf-8即可。

推荐:《PHP视频教程

php将任意编码的内容转换成utf-8

先找出字符串本身的编码,再转换为utf-8编码。

方法

function str_to_utf8 ($str = '') {
    $current_encode = mb_detect_encoding($str, array("ASCII","GB2312","GBK",'BIG5','UTF-8')); 
    $encoded_str = mb_convert_encoding($str, 'UTF-8', $current_encode);
    return $encoded_str;
}

以上就是php如何把字符串转为utf-8的详细内容,更多请关注php中文网其它相关文章!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。