本文通过两种方法解决php中file_get_contents函数抓取https地址出错,需要的朋友可以参考下
方法一:
在php中,抓取https的网站,提示如下的错误内容:
warning: file_get_contents() [function.file-get-contents]: failed to open stream: invalid argument in i:webmyphpa.php on line 16
打开php.ini文件找到 ;extension=php_openssl.dll ,去掉双引号”;” ,重启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(https://127.0.0.1/index.php) [function.file-get-contents]: failed to open stream: invalid argument in e:\website\blog\test.php on line 25
打开php.ini找到 ;extension=php_openssl.dll ,去掉双引号”;” ,重启web服务器即可。
apache的可以同时启用mod_ssl模块测试
以上内容给大家分享了两种方法解决php中file_get_contents函数抓取https地址出错,希望对大家有所帮助。
相关推荐:
php中header用法及基本功能
php中的count函数实例详解
关于php中spl_autoload_register()函数用法详解
以上就是php中file_get_contents函数抓取https地址出错的解决方法的详细内容。