Jump to content

Please Help me with bug when I Get content by tag name: <Content> RSS XML file.


hoangthi

Recommended Posts

This is the Code i am using.

This is show error:

Fatal error: Call to a member function item() on a non-object in /home/domain/public_html/forum/file/Test.php on line 35

 

 

<?php

  $xml=("http://www.vn-zoom.com/external.php?type=RSS2&forumids=77");


$xmlDoc = new DOMDocument();
$xmlDoc->load($xml);

//get elements from "<channel>"
$channel=$xmlDoc->getElementsByTagName('channel')->item(0);
$channel_title = $channel->getElementsByTagName('title')
->item(0)->childNodes->item(0)->nodeValue;
$channel_link = $channel->getElementsByTagName('link')
->item(0)->childNodes->item(0)->nodeValue;
$channel_desc = $channel->getElementsByTagName('description')
->item(0)->childNodes->item(0)->nodeValue;

//output elements from "<channel>"
echo("<p><a href='" . $channel_link
  . "'>" . $channel_title . "</a>");
echo("<br />");
echo($channel_desc . "</p>");

//get and output "<item>" elements
$x=$xmlDoc->getElementsByTagName('item');
$i=1; // $i = 1 to n (I use For here).
  {
  $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;
  // If i remove this, it will work....////////////
$item_content=$x->item($i)->getElementsByTagName('content')
  ->item(0)->childNodes->item(0)->nodeValue;
/////////////////////////////////////////////////////
  echo ("<p><a href='" . $item_link
  . "'>" . $item_title . "</a>");
  echo ("<br />");
  echo ($item_desc . "</p>");
echo ("<br />");
  echo ($item_content . "</p>");
  }
?> 

 

Please help me Fix this Code to Get content of Tag Name <content:encoded>

Thanks

 

SimpleXML is much easier.

 

<?php 

$xml_url = 'http://www.vn-zoom.com/external.php?type=RSS2&forumids=77';

$xml = new SimpleXMLElement( $xml_url, NULL, TRUE );

// Loop through <channel> -> <item>
foreach( $xml->channel->item as $item ) {
// Get the items in xmlns:content="http://purl.org/rss/1.0/modules/content/"
$content = $item->children('http://purl.org/rss/1.0/modules/content/');
// Echo content:encoded with a bunch of linebreaks.
echo $content->encoded."\n\n\n\n";
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.