2015-06-21 68 views
0

我得到一個空白屏幕後,我運行下面的代碼str_get_html不工作,返回空白

<?php include('simple_html_dom.php'); 
$html = getSslPage('https://www.reddit.com/r/nottheonion/comments/3aev89/kim_jongun_claims_to_have_cured_aids_ebola_and/'); 


function getSslPage($url) { 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
    curl_setopt($ch, CURLOPT_HEADER, false); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_REFERER, $url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
    $result = curl_exec($ch); 
    curl_close($ch); 
    return $result; 
} 

$html = str_get_html($html); 

echo $html; 

調試它是與其他網址有時工作中最難的部分。我想知道爲什麼頁面具有相同的DOM結構。任何人都知道爲什麼會發生?

+0

那麼str_get_html()是什麼?它不是一個核心的PHP函數 –

+0

@MarkBaker從字符串創建一個DOM對象http://simplehtmldom.sourceforge.net/manual.htm –

+0

那麼simple_html_dom函數str_get_html()返回一個__object__,不一定是你可以回顯,除非它有一個魔術__toString()方法......當你迴應它時你期望看到什麼? –

回答

2

這是因爲html字符串太大而且simple_html_dom具有可解析的最大限制。以下是你可以做些什麼來增加限制。

打開simple_html_dom.php和改變這一行

define('MAX_FILE_SIZE', 6000000); 

到更多的東西..嘗試

define('MAX_FILE_SIZE', 60000000); // add a zero at the end 

這應該解決的問題。讓我知道,如果情況並非如此。

+0

嘿非常感謝!它解決了我的問題! –

+0

很高興!如果有幫助,請'接受'答案。 – Vishwa