当file_get_contents 或者 simplexml_load_file的时候乱码
来源:互联网 发布:淘宝月老祠堂怎么样 编辑:程序博客网 时间:2024/04/30 03:48
乱码有几种可能如下:
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解密的时候,出现乱码或者是解不出
- 多态
- ListView分页功能(2) 自定义View实现分页功能
- 数据结构之-栈(Java实现)
- session 如 mysql
- Handler 闪屏页小应用
- 当file_get_contents 或者 simplexml_load_file的时候乱码
- Android自定义Viewpager指示器PagerIndicator-仿微博头条效果
- USACO 4.2.1 iSap + gap优化
- JAVA实现快速排序
- 从头到尾彻底理解KMP
- NYOJ矩形的个数
- http请求状态码
- 190. Reverse Bits
- ajax 多文件上传