2013-03-04 76 views
0

我正在使用一個html解析器來抓取html,然後格式化它,以便它可以插入到數據庫中。重新聲明file_get_html()的方法?

require_once('simple_html_dom.php'); 

$url = "http://www.site.com/url/params/" 
$html = file_get_html($url); 

// The team links are stored in the div.thumbHolder 
foreach($html->find('.logoWall li') as $e) 
{ 
    ob_start(); 
    sportPics($e, $league); 
} 

的sportsPics()函數是這樣的:

function sportsPic() 
{ 
    require('simple_html_dom.php'); 

    foreach($e->find('a') as $a) 
    { 
//    Execute code      
    } 
} 

我得到一個錯誤閱讀:

Fatal error: Cannot redeclare file_get_html() 

我以爲改變需要()來require_once(),反之亦然會工作。但是,它沒有。我也認爲緩衝區可能工作,但我不太瞭解他們的工作方式。

+0

變化'require'到'require_once' – 2013-03-04 04:00:25

+2

你不需要第二個要求 – ElefantPhace 2013-03-04 04:00:35

+0

這樣做,讓我:致命錯誤:調用一個成員函數查找()一個非對象 – Lance 2013-03-04 04:01:39

回答

3

不要再這樣做 -

require('simple_html_dom.php'); 

sportsPic()功能。您的功能定義function sportsPic()不帶參數。但看看這一行 -

sportPics($e, $league); 

重新定義您的函數採取參數。

您正在傳遞參數,但函數無法訪問它們,因爲它沒有參數。因此,你的$e是一個非對象。

+1

+1了罵! – ElefantPhace 2013-03-04 04:01:50

+0

這樣做給了我:致命錯誤:調用一個非對象的成員函數find() – Lance 2013-03-04 04:02:32

+0

@Lance我更新了我的答案。再次嘗試代碼。 – ShuklaSannidhya 2013-03-04 04:04:03

0

又打消了這個雙面sportsPic()函數

require('simple_html_dom.php'); 

你又&再次在循環中調用此。

0
foreach($html->find('.logoWall li') as $e){ 
    foreach($e->find('a') as $a){ 
     // Execute code 
    } 
}