扫码关注官方订阅号
iconv('GBK','UTF-8',$str) 如果$str本来就是utf-8 是不是会乱码?
认证高级PHP讲师
是会乱码的,判断一下就好了
echo mb_detect_encoding($str,'UTF-8,GBK')!='UTF-8'?iconv('GBK','UTF-8',$str):$str;
尝试了一下,是直接报错吧,Detected an illegal character in input string
先判断是不是utf8,再转码吧,这样保险点mb_detect_encoding — 检测字符的编码
试试不就知道了
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
是会乱码的,判断一下就好了
尝试了一下,是直接报错吧,Detected an illegal character in input string
先判断是不是utf8,再转码吧,这样保险点
mb_detect_encoding — 检测字符的编码
试试不就知道了