php抓取https的内容的代码

yipeiwu_com5年前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 class crawler{ private $_depth=5; pr...

PHP如何抛出异常处理错误

首先要知道什么是PHP异常? 异常(Exception)用于在指定的错误发生时改变脚本的正常流程。 PHP 5 提供了一种新的面向对象的错误处理方法。 异常处理用于在指定的错误(异常)情...

php 如何获取文件的后缀名

比如图片文件的后缀,jpg或gif等 有两个方法 一,假如$img为图片文件名 $img=12345.gif; $img_ext = substr($img, strrpos($im...

PHP获取网站域名和地址的代码

复制代码 代码如下:<? function PMA_getenv($var_name) { if (isset($_SERVER[$var_name])) { return $_S...