深入file_get_contents函数抓取内容失败的原因分析
2013-06-25 00:00
656 查看
用file_get_contents来抓取页面内容不成功,可能是因为有些主机服务商把php的allow_url_fopen选项是关闭了,就是没法直接使用file_get_contents来获取远程web页面的内容。那就是可以使用另外一个函数curl。
下面是file_get_contents和curl两个函数同样功能的不同写法
file_get_contents函数的使用示例:
换成curl函数的使用示例:
下面是file_get_contents和curl两个函数同样功能的不同写法
file_get_contents函数的使用示例:
< ?php $file_contents = file_get_contents(‘http://www.jb51.net'); echo $file_contents; ?>
换成curl函数的使用示例:
< ?php $ch = curl_init(); $timeout = 5; curl_setopt ($ch, CURLOPT_URL, ‘http://www.jb51.net'); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $file_contents = curl_exec($ch); curl_close($ch); echo $file_contents; ?>
相关文章推荐
- file_get_contents函数抓取内容失败分析
- 抓取网页内容,用file_get_contents函数
- php利用file_get_contents函数抓取网页指定内容
- PHP中file_get_contents函数抓取https地址出错的解决方法
- “undefined reference to JNI_GetCreatedJavaVM”和“File format not recognized”错误原因分析
- 关于php服务器代理上网的时候使用file_get_contents函数取不到内容的问题的解决方案
- PHP5中file_get_contents函数获取带BOM的utf-8文件内容时需注意
- PHP中file_get_contents函数抓取https地址出错的解决方法(两种方法)
- 经典抓取网络数据方法效率分析(fsockopen/curl/file_get_contents)
- PHP5中file_get_contents函数获取带BOM的utf-8文件内容时需注意
- GetFileVersionInfo 获取文件版本信息错误原因分析
- 关于测试curl 与file_get_contents抓取内容效率及稳定性
- 学习php需要了解的点4 - PHP中file_get_contents函数抓取https地址出错的解决方法
- file_get_contents获取json内容处理失败的问题
- php中的file_get_contents函数------获取文件内容
- “undefined JNI_GetCreatedJavaVM”和“File format not recognized”错误原因分析
- js 获取位置信息方法 navigator.geolocation.getCurrentPosition 失败原因分析
- php -- PHP5中file_get_contents函数获取带BOM的utf-8文件内容
- php使用file_get_contents函数抓取页面信息