获取网页内容时的乱码问题
2013-03-09 09:11
232 查看
现在总结有两个原因:
1.编码问题。
解决:
2.目标页面开了Gzip
解决:@curl获取时
@file_get_contents获取时
1.编码问题。
解决:
<?php $url = "http://news.ef360.com/Articles/2013-3-8/299954.html"; $contents=file_get_contents($url); $contents=iconv("GBK", "UTF-8//IGNORE", $contents); echo $contents; ?>
2.目标页面开了Gzip
解决:@curl获取时
<?php function curl_get($url, $gzip=false){ $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10); if($gzip) curl_setopt($curl, CURLOPT_ENCODING, "gzip"); // 关键在这里 $content = curl_exec($curl); curl_close($curl); return $content; } ?>
@file_get_contents获取时
<?php file_get_contents("compress.zlib://".$url); ?>
相关文章推荐
- php file_get_contents获取网页内容gzip编码导致的乱码问题
- c#远程获取网页内容及乱码问题的解决办法
- C#获取网页内容,解决大部分乱码问题
- c#远程获取网页内容及乱码问题的解决办法 .
- 获取网页内容时的乱码问题
- c#远程获取网页内容及乱码问题的解决办法 .
- HttpURLConnection 从网页获取内容与乱码问题解决
- c# 采集 获取网页数据内容 一会超时的问题
- 抓取网页中的内容、如何解决乱码问题、如何解决登录问题以及对所采集的数据进行处理显示的过程
- VC 获取网页数据时,如何解决乱码问题
- curl获取网页内容出现乱码或为空的解决方案,另附curl_getinfo函数解析
- 利用HttpWebRequest获取网页内容,由于Gzip压缩导致乱码的情况
- Java网页抓取网页内容时,乱码问题的解决
- 使用WebBrowser获取网页源代码,解决中文乱码问题
- HttpWebResponse无法准确获取CharacterSet导致网页数据乱码问题的解决
- delphi2009 用idhttp获取网页内容中文乱码
- 使用TIdHTTP获取网页的中文乱码问题
- node js 抓取指定网页内容gb2312乱码问题解决
- .NET中获取网页乱码问题
- c# 获取网页源代码(可解决某些页面乱码的问题)