解决PHP中file-get-contents函数的方法

方法一:

解决PHP中file-get-contents函数的方法

在php中,抓取https的`网站,提示如下的错误内容:

Warning: file_get_contents() [-get-contents]: failed to open stream: Invalid argument in I: on line 16

打开文件找到 ;extension=php_ ,去掉双引号”;” ,重启web服务器即可。

apache服务器的话,可以同时启用mod_ssl模块测试。

如果不方便修改服务器配置,可以参考使用如下的函数来解决:

代码示例:

<?php//file_get_contents抓取https地址内容function getCurl($url){$ch = curl_init();curl_setopt($ch, CURLOPT_URL,$url);curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);$result = curl_exec($ch);curl_close ($ch);return $result;}

方法二:

在php中,利用file_get_contents函数抓取url是https开头的网站网页内容时,会出现类似下面的错误警告:

Warning: file_get_contents() [-get-contents]: failed to open stream: Invalid argument in E: on line 25

打开找到 ;extension=php_ ,去掉双引号”;” ,重启web服务器即可。

apache的可以同时启用mod_ssl模块测试