php抓取https的内容的代码

yipeiwu_com6年前PHP代码库
直接用file_get_contents,会报错;

复制代码 代码如下:

$url = (https://xxx.com");
file_get_contents($url);

错误:
Warning: file_get_contents(https://xxx.com) [function.file-get-contents]: failed to open stream: No such file or directory in D:wampwwwgrabber_clientindex.php on line 3

用curl的方式是可以的:
复制代码 代码如下:

$url = (https://xxx.com);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$result = curl_exec($ch);
print_r($result);
?>

重点是以下两句:
复制代码 代码如下:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

相关文章

PHP切割汉字的常用方法实例总结

本文实例讲述了PHP切割汉字的常用方法。分享给大家供大家参考,具体如下: <?php /* @UTF-8编码的字符可能由1~3个字节组成。 */ /*---------...

php对关联数组循环遍历的实现方法

本文实例讲述了php对关联数组循环遍历的实现方法。分享给大家供大家参考。具体分析如下: php对于类似 $age = array("zhangshan"=>14,"lisi"...

php计算年龄精准到年月日

本文实例讲述了php计算年龄精准到年月日的方法。分享给大家供大家参考。具体如下: <?php /* * To change this license header...

php sprintf()函数让你的sql操作更安全

$bookSQL=sprintf("UPDATE book SET pass=%s WHERE id=%d",   ...

PHP实现的json类实例

本文实例讲述了PHP实现的json类。分享给大家供大家参考。具体如下: 这里注意json_encode只有(PHP 5 >= 5.2.0, PECL json >= 1.2....