php file_get_contents返回空 无效解决办法
2015-07-05 17:21
896 查看
[导读] file_get_contents函数多用来于来采集远程服务器上的内容,但使用file_get_contents函数之前我们在php ini中是必须把allow_url_fopen开启才行问题描述fopen(),file_get_contents(),getimagesize() 等都不能正
file_get_contents函数多用来于来采集远程服务器上的内容,但使用file_get_contents函数之前我们在php.ini中是必须把allow_url_fopen开启才行
问题描述
fopen(),file_get_contents(),getimagesize() 等都不能正常获得网络上的内容,具体表现为凡参数是URL的,一律返回空值
如果是windows可找开
allow_url_fopen开启
如果是否linux中可以
重新编译PHP,去掉–with-curlwrapper 参数——编译前记得先执行 make clean。
windows 在未开户allow_url_fopen时我们利用
是获取不到值的,但我们可以利用function_exists来判断此函数是否可用。
file_get_contents函数多用来于来采集远程服务器上的内容,但使用file_get_contents函数之前我们在php.ini中是必须把allow_url_fopen开启才行
问题描述
fopen(),file_get_contents(),getimagesize() 等都不能正常获得网络上的内容,具体表现为凡参数是URL的,一律返回空值
如果是windows可找开
allow_url_fopen开启
如果是否linux中可以
重新编译PHP,去掉–with-curlwrapper 参数——编译前记得先执行 make clean。
windows 在未开户allow_url_fopen时我们利用
代码如下 | 复制代码 |
< ?php $file_contents = file_get_contents(''http://www.php100.com/''); echo $file_contents; ?> |
代码如下 | 复制代码 |
function file_get_content($url) { if (function_exists(‘file_get_contents')) { $file_contents = @file_get_contents($url); } if ($file_contents == ”) { $ch = curl_init(); $timeout = 30; 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; } |
相关文章推荐
- DedeAMPZ配置php的curl扩展
- 如何创建phpinfo查看php信息?
- PHP 错误与异常 笔记与总结(15 )使用观察者模式处理异常信息
- PHP常用功能模块
- ubuntu 14.04 安装php环境
- PHP生成唯一订单号
- php结合imgareaselect实现图片裁剪
- PHP json_encode出现乱码的问题
- php超快高效率统计大文件行数
- PHP版QQ互联OAuth示例代码分享
- PHP 获取ip地址代码汇总
- PHP中$_SERVER使用说明
- php实现短信发送代码
- php 字符串函数
- 【PHP】基础学习
- php将图片以二进制保存到mysql数据库并显示
- phpMyAdmin登陆方法
- phpcms站---去除域名绑定目录中的HTML
- PHP 7 新增内容介绍
- vsftp软链接ln遇到550错误