楚奇游戏网
您的当前位置:首页php如何把字符串转为utf-8

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

来源:楚奇游戏网


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;
}
显示全文