php把字符串转为utf - 8的方法

  介绍

小编给大家分享一下php把字符串转为utf - 8的方法,希望大家阅读完这篇文章后大所收获、下面让我们一起去探讨吧!

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

 php把字符串转为utf - 8的方法

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

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

方法

函数str_to_utf8 ($ str=& # 39; & # 39;) {   (current_encode=mb_detect_encoding美元str,阵列(“ASCII",“GB2312",“GBK", & # 39;繁体# 39;,& # 39;utf - 8 # 39;));   (encoded_str=mb_convert_encoding美元str, & # 39; utf - 8 # 39;, current_encode美元);   返回encoded_str美元;   }

看完了这篇文章,相信你对php把字符串转为utf - 8的方法有了一定的了解,想了解更多相关知识,欢迎关注行业资讯频道,感谢各位的阅读!

php把字符串转为utf - 8的方法