-1

I try to scrap an feed using below PHP code

$x=$xmlDoc->getElementsByTagName('item');

for ($i=0; $i<=5; $i++) {
  $item_title=$x->item($i)->getElementsByTagName('title')
  ->item(0)->childNodes->item(0)->nodeValue;

  $item_link=$x->item($i)->getElementsByTagName('link')
  ->item(0)->childNodes->item(0)->nodeValue;

  $item_desc=$x->item($i)->getElementsByTagName('description')
  ->item(0)->childNodes->item(0)->nodeValue;

  $item_content=$x->item($i)->getElementsByTagName('content:encoded')
  ->item(0)->childNodes->item(0)->nodeValue;

  echo ("<p><a href='" . $item_link
  . "'>" . $item_title . "</a>");
  echo ("<br>");
  echo ($item_desc . "</p>");
}

but I got an error Notice: Trying to get property of non-object in the line of $item_content, why? This is the feed link http://www.rotikaya.com/feed/

1 Answers1

0

The error Notice: Trying to get property of non-object means that you try to access an object that does not exists. Check the line of the error message and your code and make sure that a) the feedobject you want to read does exists and b) the index of it you want to read the data from with your $i variable.

The using of var_dump($variable) should help you debugging your code and to find out which object / index is not existing.

bish
  • 3,381
  • 9
  • 48
  • 69