赞
踩
在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()会使用了吧。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。