file_get_contents函数不能使用的解决方法
来源:互联网 发布:显示qqip地址软件 编辑:程序博客网 时间:2024/06/06 02:28
有些主机服务商把php的allow_url_fopen选项是关闭了,就是没法直接使用file_get_contents来获取远程web页面的内容。那就是可以使用另外一个函数curl。
下面是file_get_contents和curl两个函数同样功能的不同写法
file_get_contents函数的使用示例:
< ?php $file_contents = file_get_contents('http://www.ccvita.com/'); echo $file_contents; ?>
换成curl函数的使用示例:
< ?php $ch = curl_init(); $timeout = 5; curl_setopt ($ch, CURLOPT_URL, 'http://www.ccvita.com'); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $file_contents = curl_exec($ch); curl_close($ch); echo $file_contents; ?>
利用function_exists函数来判断php是否支持一个函数可以轻松写出下面函数
< ?php function vita_get_url_content($url) { if(function_exists('file_get_contents')) { $file_contents = file_get_contents($url); } else { $ch = curl_init(); $timeout = 5; curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $file_contents = curl_exec($ch); curl_close($ch); } return $file_contents; } ?>
其实上面的这个函数还有待商榷,如果你的主机服务商把file_get_contents和curl都关闭了,上面的函数就会出现错误。
0 0
- file_get_contents函数不能使用的解决方法
- file_get_contents函数不能使用的解决方法
- file_get_contents函数不能使用的解决方法
- file_get_contents 的使用
- PHP中file_get_contents、fp_open等不能使用!
- file_get_contents无法请求https连接的解决方法
- file_get_contents无法请求https连接的解决方法
- file_get_contents无法请求https连接的解决方法
- file_get_contents无法请求https连接的解决方法
- php 使用file_get_contents的问题
- PHP file_put_contents&file_get_contents的使用
- file_get_contents使用
- PHP file_get_contents 函数获取URL的处理
- MySQL函数不能创建的解决方法
- MySQL函数不能创建的解决方法
- MySQL函数不能创建的解决方法
- 学习php需要了解的点4 - PHP中file_get_contents函数抓取https地址出错的解决方法
- 关于linux下面的file_get_contents的使用
- Android Studio开发工具学习篇章二----Gradle的学习
- 社交类网站常用jquery库
- AS:Error running app: Instant Run requires 'Tools | Android | Enable ADB integration' to be enabled.
- OAuth2.0认证和授权原理
- AndFix热修复实现
- file_get_contents函数不能使用的解决方法
- hdu 5667 BestCoder Round #80 矩阵快速幂
- PHP导入excel
- 【全网独享】基于springMvc经过改装的js+ajax的省市地区县街道四级联动弹出框(网上的都是三级联动的哦)
- button的使用方法
- TCP三次握手/四次挥手详解
- python3.x 学习笔记 2
- ajax提交表单时CKEDITOR不实时更新字段内容解决方法
- Android应用开发必备的20条技能清单