当file_get_contents或者simplexml_load_file的时候乱码
来源:互联网 发布:万国数据科技公司怎样 编辑:程序博客网 时间:2024/05/08 04:15
乱码有几种可能如下:
1.页面能获取过来,只是内容乱码而已:可以采用iconv()和mb_convert_encoding()函数进行转码即可
2.当内容都无法正常获取的时候,分两种情况第一种是防盗链,第二种是页面需要解压
2.1防盗链情况下解决办法比较简单,模拟浏览器就可以了
- <?php
- header('content-type:text/html;charset=utf-8');
- $url="http://www.sohu.com/";
- ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727;)');
- $html=file_get_contents($url);
- //echo $html;
- echo mb_convert_encoding($html,'utf8','gbk');
2.2需要解压时,我们可以用以下方式
- <?php
- header("content-type:text/html;charset=utf-8");
- $url="http://wthrcdn.etouch.cn/WeatherApi?city=%E5%8C%97%E4%BA%AC";
- $xml = simplexml_load_file("compress.zlib://".$url);
- $json=json_encode($xml);
- $arr=json_decode($json,true);
- print_r($arr);
0 0
- 当file_get_contents或者simplexml_load_file的时候乱码
- 当file_get_contents或者simplexml_load_file的时候乱码
- 当file_get_contents 或者 simplexml_load_file的时候乱码
- 当file_get_contents或者simplexml_load_file的时候乱码
- 当file_get_contents或者simplexml_load_file的时候乱码
- 当file_get_contents或者simplexml_load_file的时候乱码
- 当file_get_contents或者simplexml_load_file的时候乱码
- 当file_get_contents或者simplexml_load_file的时候乱码
- 当file_get_contents或者simplexml_load_file的时候乱码
- 当file_get_contents或者simplexml_load_file的时候乱码
- 当file_get_contents或者simplexml_load_file的时候乱码
- file_get_contents或者simplexml_load_file时乱码
- 用file_get_contents 或 simplexml_load_file 采集的时候乱码
- file_get_contents模拟浏览器访问的时候乱码
- file_get_contents模拟浏览器访问的时候乱码
- file_get_contents与simple_load_file的时候乱码怎么解决
- Android 当EditextText失去焦点,或者点击Activity的时候关闭软键盘或者其他布局
- base64_decode解密的时候,出现乱码或者是解不出
- 第一课:初识JAVA
- android6.0以后动态获取权限
- mysql 主从原理
- div悬浮居中
- xcode7中实现界面按钮直接调转+lable控件赋值
- 当file_get_contents或者simplexml_load_file的时候乱码
- Bezier样条
- Apache日志备分,分析后导入数据表
- unity 物体间的碰撞检测
- HTML+CSS学习笔记 (九)
- Android中的定时器Timer、AlarmManager、CountDownTimer的使用
- NYoj38布线问题
- 【算法导论-36】并查集(Disjoint Set)详解
- TCP的流量控制与拥塞控制