SIMPLE HTML DOM致命错误在非对象上调用成员函数find()

时间:2013-02-08 22:46:40

标签: php

我正在使用简单的HTML DOM库并且我得到了错误

致命错误:在第14行的/home/rodingo/public_html/crawler/music.php中调用非对象的成员函数find()

但是它在localhost上正常工作但在我的专用服务器上造成了问题。 cURL,fopen一切都已启用但仍然。

 include('includes/simple_html_dom.php');

$html = file_get_html('http://mp3skull.com/mp3/'.$mp3name.'.html');
$list = array();
echo $html;
foreach ( $html->find('div#song_html ') as $e ) {  // <-- LINE 14
 $song = array();
    $song['bit'] = preg_replace('!\s+!', ' ',$e->find('div', 0)->plaintext);
    $song['title'] = preg_replace('!\s+!', ' ',$e->find('div', 1)->plaintext);
    $song['url'] = preg_replace('!\s+!', ' ',$e->find('a', 0)->href);
    $list[] = $song;
}

1 个答案:

答案 0 :(得分:1)

您使用的是简单HTML DOM,因此我假设您要使用file_get_html代替file_get_contents

file_get_contents返回一个字符串,而file_get_html返回一个HTML DOM对象。

$html = file_get_html('http://mp3skull.com/mp3/'.$mp3name.'.html');