php中文编码转换问题

coldplay.xixi
coldplay.xixi原创
2023-03-03 21:40:011662浏览

php中文编码转换的方法:1、使用iconv函数,代码为【string iconv (string $in_, string $out_, string $str)】;2、使用【mb_convert_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;

在这里插入图片描述

e39334fc8485b4640422b3fb951c226.png

相关学习推荐:php编程(视频)

以上就是php中文编码转换问题的详细内容,更多请关注php中文网其它相关文章!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。