php汉字编码转换的方法:1、使用“string iconv()”方法进行转换;2、通过“mb_convert_encoding”方法进行转换;3、使用“mb_detect_encoding”方法进行转换。
推荐:《PHP视频教程》
string iconv ( string $in_charset , string $out_charset , string $str )
第一个参数:内容原的编码
第二个参数:目标编码
第三个参数:要转的字符串
$filename='我爱你中国';$filename = iconv('gbk','utf-8',$filename);
解析:把$filename从gbk转换为utf8
string mb_convert_encoding ( string $str , string $to_encoding [, mixed $from_encoding ] )
第一个参数:要处理的字符串
第二个参数:目标编码
第三个参数:内容原编码
立即学习“PHP免费学习笔记(深入)”;
$filename='我爱你中国';$filename = mb_convert_encoding($filename,'GBK','UTF-8');
解析:把$filename从utf8转换为gbk
$filename='我爱你中国';$encode = mb_detect_encoding($filename, array("ASCII","UTF-8","GB2312","GBK","BIG5"));echo $encode;die;
以上就是php汉字编码转换的方法的详细内容,更多请关注php中文网其它相关文章!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号