《PHP教程:PHP中file_get_contents函數(shù)抓取https地址出錯(cuò)的解決方法(兩種方法)》要點(diǎn):
本文介紹了PHP教程:PHP中file_get_contents函數(shù)抓取https地址出錯(cuò)的解決方法(兩種方法),希望對您有用。如果有疑問,可以聯(lián)系我們。
辦法一:PHP學(xué)習(xí)
在php中,抓取https的網(wǎng)站,提示如下的錯(cuò)誤內(nèi)容:
PHP學(xué)習(xí)
Warning: file_get_contents() [function.file-get-contents]: failed to open stream: Invalid argument in I:Webmyphpa.php on line 16PHP學(xué)習(xí)
打開php.ini文件找到 ;extension=php_openssl.dll ,去掉雙引號”;” ,重啟web服務(wù)器即可.PHP學(xué)習(xí)
apache服務(wù)器的話,可以同時(shí)啟用mod_ssl模塊測試.
PHP學(xué)習(xí)
如果不方便修改服務(wù)器配置,可以參考使用如下的函數(shù)來解決:PHP學(xué)習(xí)
代碼示例:
PHP學(xué)習(xí)
<?php //file_get_contents抓取https地址內(nèi)容 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學(xué)習(xí)
在php中,利用file_get_contents函數(shù)抓取url是https開頭的網(wǎng)站網(wǎng)頁內(nèi)容時(shí),會(huì)出現(xiàn)類似下面的錯(cuò)誤警告:PHP學(xué)習(xí)
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 25PHP學(xué)習(xí)
打開php.ini找到 ;extension=php_openssl.dll ,去掉雙引號”;” ,重啟web服務(wù)器即可.PHP學(xué)習(xí)
apache的可以同時(shí)啟用mod_ssl模塊測試PHP學(xué)習(xí)
以上內(nèi)容給大家分享了兩種辦法解決PHP中file_get_contents函數(shù)抓取https地址出錯(cuò),希望對大家有所幫助.PHP學(xué)習(xí)
維易PHP培訓(xùn)學(xué)院每天發(fā)布《PHP教程:PHP中file_get_contents函數(shù)抓取https地址出錯(cuò)的解決方法(兩種方法)》等實(shí)戰(zhàn)技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培養(yǎng)人才。
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.fzlkiss.com/jiaocheng/8727.html