2017-10-16 69 views
0

我遇到的問題是如下:獲得的file_get_contents錯誤 - simple_html_dom.php XAMPP

Warning: file_get_contents(): Unable to find the wrapper "https" - 
did you forget to enable it when you configured PHP? in 
<b>C:\xampp\htdocs\test_crawl\simple_html_dom.php</b> on line <b>75</b><br 
/> 
<br /> 
<b>Warning</b>: file_get_contents(https://www.yahoo.com): failed to open 
stream: Invalid argument in 
<b>C:\xampp\htdocs\test_crawl\simple_html_dom.php</b> on line <b>75</b><br 
/> 

我做了一些研究,我發現了幾個職位,說取消註釋在php.ini作品extension=php_openssl.dll但是當我沒有和我重新開始服務器它沒有我習慣not.The腳本如下:

$url = 'https://yahoo.com' 
function CrawlMe($url) 
{ 
$html = file_get_html($url); 
return json_encode($html); 
} 

不知道爲什麼它不工作會感謝你的幫助..

下面是一個真實示數出在$contents = file_get_contents($url, $use_include_path, $context, $offset);

function file_get_html($url, $use_include_path = false, $context=null, 
$offset = -1, $maxLen=-1, $lowercase = true, $forceTagsClosed=true, 
$target_charset = DEFAULT_TARGET_CHARSET, $stripRN=true, 
$defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT) 
{ 
// We DO force the tags to be terminated. 
$dom = new simple_html_dom(null, $lowercase, $forceTagsClosed, 
$target_charset, $stripRN, $defaultBRText, $defaultSpanText); 
// For sourceforge users: uncomment the next line and comment the 
// retreive_url_contents line 2 lines down if it is not already done. 
$contents = file_get_contents($url, $use_include_path, $context, $offset); 
// Paperg - use our own mechanism for getting the contents as we want to 
control the timeout. 
//$contents = retrieve_url_contents($url); 
if (empty($contents) || strlen($contents) > MAX_FILE_SIZE) 
{ 
    return false; 
} 
// The second parameter can force the selectors to all be lowercase. 
$dom->load($contents, $lowercase, $stripRN); 
return $dom; 
} 

回答

0

什麼在simple_html_dom.php的75線的功能?從已發佈的所有我能說的是

$url = 'https://yahoo.com' 

缺少一個分號,它應該是:

看到的代碼之後
$url = 'https://yahoo.com'; 

- 編輯...

你是將偏移量設置爲-1。這意味着從文件末尾開始讀取。根據文檔

遠程文件不支持尋找(偏移量)。試圖在非本地文件上搜索 可能會使用較小的偏移量,但這是 不可預知的,因爲它適用於緩衝流。

你的maxlength被設定爲減1作爲每documaentation:

如果文件名不能被發現,將產生一個E_WARNING電平誤差, 最大長度小於零,或者如果尋求到指定的在 中抵消流失敗。

你並不需要指定所有這些參數,這將很好地工作:

$file = file_get_contents('https://www.yahoo.com'); 
+0

線75:'$內容=的file_get_contents($網址,$ use_include_path,$背景下,$偏移); ' –

+0

...以及那些變量設置爲?如果你只是發佈所有的代碼,它會容易得多。 – miknik

+0

這裏是[函數定義](http://sandbox.onlinephpfunctions.com/code/c86f20d4667405d27ac212a1130b9a857468e74a) –