php file_get_contents 失效,phpfile_get_contents返回空无效解决办法_PHP教程

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.bkjia.com/'');

echo $file_contents;

?>

是获取不到值的,但我们可以利用function_exists来判断此函数是否可用。

代码如下

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;

}

http://www.bkjia.com/PHPjc/445629.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/445629.htmlTechArticlefile_get_contents函数多用来于来采集远程服务器上的内容,但使用file_get_contents函数之前我们在php.ini中是必须把allow_url_fopen开启才行 问题描述...

本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉 本文系统来源:php中文网

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值