2013-08-13 3 views
2

PHP를 처음 사용합니다.
나는 점점치명적 오류 : 비 객체에서 find() 멤버 함수를 호출하십시오.

Fatal error: Call to a member function find() on a non-object error,

나는 simple_html_dom.php 포함

<?php 
include 'simple_html_dom.php'; 
$htm = file_get_html('http://www.thatscricket.com'); 

$es = $htm->find('div[class=score_card_display_below_links]'); 

$value = $es[0]->href; 

$link = "http://www.thatscricket.com/$value"; 

$html = file_get_html('$link'); 

$scr = $html->find('span'); 

echo "$scr"; 
?> 
+0

가능한 복제본 [PHP 간단한 HTML DOM 파서를 사용하는 이상한 오류] (http://stackoverflow.com/questions/6832197/weird-error-using-php-simple-html-dom-parser) –

답변

2
$html = file_get_html('$link'); 

이 리터럴 문자열 '$link'을 얻기 위해 노력할 것입니다 (변수는 단일 인용 문자열 내에서 확장되지 않습니다). 즉, $html은 null 또는 false입니다.

$html은 개체가 아니기 때문에 메서드를 호출 할 수 없습니다.

사용 :

$html = file_get_html($link); 

또한 항상 정상적으로 실패 할 수 있도록 인해 실패 허위 또는 null의 경우도있다 형태를 돌려 확인해야합니다.

0
$htm = file_get_html('http://www.thatscricket.com'); 

체크 var_dump($htm); 나는 그것을 반환 생각 bool(false)

$html = file_get_html('$link'); 

해야한다
$html = file_get_html($link); 
0

확인 var_dump($htm) 첫째, 그것은 반환해야 널

0
나는 또한 같은 오류가 발생한

내가 찾은 그것이 내가이 방법에서 잘 작동합니다 희망이

if($htm){ 
    $score_card_count = count($htm->find('div[class=score_card_display_below_links]')); 
    $score_card_count = trim($score_card_count); 
     if($score_card_count > 0) 
     { 
       $es = $htm->find('div[class=score_card_display_below_links]'); 
       $value = $es[0]->href; 
     } 
} 

으로 PHP 카운트 기능에서 솔루션 내 오류가 수정되었습니다.

관련 문제