PHP - Call to a member function find() on a non-object

前端 未结 2 1811
Happy的楠姐
Happy的楠姐 2021-01-29 00:31

So this error is killing me, heres the code:

$html = file_get_html(\'vids.html\');

foreach($html->find(\'a\') as $element) {

        echo $element->name
         


        
2条回答
  •  后悔当初
    2021-01-29 01:20

    I think you should var_dump($element) inside the loop and see if it has the 'name' property set. YOu could modify your condition and add isset() in the loop,

       foreach($html->find('a') as $element) {
         if(isset($element->name)){
            echo $element->name;
         }
      }
    

提交回复
热议问题