当前位置:Gxlcms > PHP教程 > php汉字编码转换的方法

php汉字编码转换的方法

时间:2021-07-01 10:21:17 帮助过:94人阅读

php汉字编码转换的方法:1、使用“string iconv()”方法进行转换;2、通过“mb_convert_encoding”方法进行转换;3、使用“mb_detect_encoding”方法进行转换。

推荐:《PHP视频教程》

一、iconv

string iconv ( string $in_charset , string $out_charset , string $str )
第一个参数:内容原的编码
第二个参数:目标编码
第三个参数:要转的字符串

$filename='我爱你中国';$filename = iconv('gbk','utf-8',$filename);

解析:把$filename从gbk转换为utf8

二、mb_convert_encoding

string mb_convert_encoding ( string $str , string $to_encoding [, mixed $from_encoding ] )
第一个参数:要处理的字符串
第二个参数:目标编码
第三个参数:内容原编码

$filename='我爱你中国';$filename = mb_convert_encoding($filename,'GBK','UTF-8');

解析:把$filename从utf8转换为gbk

三、mb_detect_encoding查看字符编码

$filename='我爱你中国';$encode = mb_detect_encoding($filename, array("ASCII","UTF-8","GB2312","GBK","BIG5"));echo $encode;die;

在这里插入图片描述

以上就是php汉字编码转换的方法的详细内容,更多请关注gxlcms其它相关文章!

人气教程排行