PHP中file_get_contents函数抓取https地址出错的解决方
网络编程 2021-07-05 09:09www.168986.cn编程入门
本文通过两种方法解决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_set($ch, CURLOPT_URL,$url); curl_set($ch, CURLOPT_RETURNTRANSFER,1); curl_set($ch, CURLOPT_SSL_VERIFYPEER, false); curl_set($ch, CURLOPT_SSL_VERIFYHOST, false); $result = curl_exec($ch); curl_close ($ch); return $result; }
方法二:
在php中,利用file_get_contents函数抓取url是https开头的网站网页内容时,会出现类似狼蚁网站SEO优化的错误警告:
Warning: file_get_contents() [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地址出错,希望对大家有所帮助。
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程