2017-09-19 5 views
0
if ($rows->length > 0) 
    { 
    for ($i=1; $i<=$rows->length ; $i++) 
    { 
     //echo($rows[$i]->getElementsByTagname('th')); 
     $cols = $rows->item($i)->getElementsByTagname('td'); 
     for ($j=0; $j <$cols->length ; $j++) 
     { 
      //echo($cols[$j]->nodeValue); 
      $input_lines = $cols[$j]->nodeValue; 
      $input_lines = preg_replace("/\D/", "", $input_lines); 
      echo $input_lines; 
      echo"<br><br>"; 

     }  
     } 
    } 

Fatal error: Call to a member function getElementsByTagname() on null치명적인 오류 : 널 (null)에 멤버 함수 getElementsByTagname()를 호출

+1

은 객체 메소드 또는 속성 인'$ rows-> item'입니까? –

+1

echo $ rows-> item ($ i)을 표시 할 수 있습니까? ? – akbansa

답변

0

당신이하지 null이 변수를 확인하기 위해 필요하므로 getElementsByTagName는 NULL (문서 here 주문에 따라)를 반환 할 수있어서

$cols = $rows->item($i) 
if(!null($cols)){ 
    $cols = $cols->getElementsByTagname('td') 
} 
else { 
    throw new Exception("Element with name 'some name' was not found"); 
} 
관련 문제