打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
PHP错误:iconv() Detected an illegal character

 

  1. <?php  
  2. @header("Content-type:text/html;charset=GB2312");  
  3. $arr = array ('name'=>"贾朝藤",'age'=>19,'sex'=>"男",'add'=>"中国石家庄");  
  4. echo json_encode($arr);  
  5. echo "<br/>";  
  6. $name = iconv("GBK","UTF-8","贾朝藤");  
  7. $sex = iconv("GBK","UTF-8","男");  
  8. $add = iconv("GBK","UTF-8","中国石家庄");  
  9. $arr = array ('name'=>"$name",'age'=>19,'sex'=>"$sex",'add'=>"$add");  
  10. echo $str=json_encode($arr);  
  11. ?>  

  错误信息如下:

  1. {"name":"/u8d3e/u671d/u85e4","age":19,"sex":"/u7537","add":"/u4e2d/u56fd/u77f3/u5bb6/u5e84"} Notice: iconv() [function.iconv]: Detected an illegal character in input string in D:/wamp/www/ajax/js_php.php on line 6 Notice: iconv() [function.iconv]: Detected an illegal character in input string in D:/wamp/www/ajax/js_php.php on line 7 Notice: iconv() [function.iconv]: Detected an illegal character in input string in D:/wamp/www/ajax/js_php.php on line 8 {"name":"/u7490/u70ac","age":19,"sex":"","add":"/u6d93"}   

  之后百度,谷歌了一番,得到两个方法:
  1.把gb2312换为gbk ,同样出错,错误信息如下

  1. "name":"/u8d3e/u671d/u85e4","age":19,"sex":"/u7537","add":"/u4e2d/u56fd/u77f3/u5bb6/u5e84"}  
  2. Notice: iconv() [function.iconv]: Detected an incomplete multibyte character in input string in D:/wamp/www/ajax/js_php.php on line 6  
  3. Notice: iconv() [function.iconv]: Detected an incomplete multibyte character in input string in D:/wamp/www/ajax/js_php.php on line 7  
  4. Notice: iconv() [function.iconv]: Detected an illegal character in input string in D:/wamp/www/ajax/js_php.php on line 8  
  5. {"name":"/u7490/u70ac/u6e5e/u9498","age":19,"sex":"/u9422","add":"/u6d93"}  

  2.在UTF-8后加//IGNORE ,加上后提示如下:

  1. {"name":"/u8d3e/u671d/u85e4","age":19,"sex":"/u7537","add":"/u4e2d/u56fd/u77f3/u5bb6/u5e84"}  
  2. Notice: iconv() [function.iconv]: Detected an incomplete multibyte character in input string in D:/wamp/www/ajax/js_php.php on line 6  
  3. Notice: iconv() [function.iconv]: Detected an incomplete multibyte character in input string in D:/wamp/www/ajax/js_php.php on line 7  
  4. {"name":"/u7490/u70ac/u6e5e/u9498","age":19,"sex":"/u9422","add":"/u6d93/u9365/u754c/u7176/u7039/u8dfa/u7c1e"}  

  不解,之后在论坛提问,得到问题所在:

  我的php文件本身是utf-8编码的,把它转为ansi这个问题就不存在

  修改之后,确实,显示正常了!

或者

return iconv('utf-8//ignore','gbk//ignore',$utfstr); 

替换为

mb_convert_encoding($utfstr, "UTF-8", "GBK");

 

来源:https://www.icode9.com/content-1-897851.html
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
PHP编码转换和PHP编码判断
PHP 不使用插件导出excel的简单方法
js,ajax,php打造进度条
科普:宽字节注入详解
php 判断中文 utf8,PHP 判断 UTF
php中iconv函数使用方法
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服