当前位置:   article > 正文

php中文转码mb_convert_encoding()函数的使用_php mb_convert_encoding

php mb_convert_encoding

在php开发中,有时候会遇到头疼的中文编码的处理问题。比如gbK转换为utf8,utf8转化为gbk等。下面就介绍一个php函数mb_convert_encoding()函数的使用。看它如何实现中文编码的自由转化。

使用:

mb_convert_encoding( $str, e n c o d i n g 1 , encoding1, encoding1,encoding2)
参数:

$str, 要转换编码的字符串

$encoding1,目标编码,如utf-8,gbk,大小写均可

$encoding2,原编码,如utf-8,gbk,大小写均可
范例一:

s t r = ′ 编 码 ′ ; e c h o m b c o n v e r t e n c o d i n g ( str='编码'; echo mb_convert_encoding( str=;echombconvertencoding(str, “UTF-8”); //编码转换为utf-8
范例二:

s t r = ′ 编 码 ′ ; e c h o m b c o n v e r t e n c o d i n g ( str='编码'; echo mb_convert_encoding( str=;echombconvertencoding(str, “UTF-8”, “GBK”); //已知原编码为GBK,转换为utf-8
范例三:

s t r = ′ 编 码 ′ ; e c h o m b c o n v e r t e n c o d i n g ( str='编码'; echo mb_convert_encoding( str=;echombconvertencoding(str, “UTF-8”, “auto”); //未知原编码,通过auto自动检测后,转换编码为utf-8
看完介绍,上面的php中文转码函数mb_convert_encoding()会使用了吧。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/531835
推荐阅读
相关标签
  

闽ICP备14008679号