hoangthi Posted October 17, 2011 Share Posted October 17, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/249290-please-help-me-with-bug-when-i-get-content-by-tag-name-rss-xml-file/ Share on other sites More sharing options...
xyph Posted October 18, 2011 Share Posted October 18, 2011 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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/249290-please-help-me-with-bug-when-i-get-content-by-tag-name-rss-xml-file/#findComment-1280083 Share on other sites More sharing options...
hoangthi Posted October 18, 2011 Author Share Posted October 18, 2011 Please Help me Fix my code. Because I use Loop "For" for this code. Quote Link to comment https://forums.phpfreaks.com/topic/249290-please-help-me-with-bug-when-i-get-content-by-tag-name-rss-xml-file/#findComment-1280105 Share on other sites More sharing options...
hoangthi Posted October 18, 2011 Author Share Posted October 18, 2011 I want to Get Each Value of Content by using Loop "for" Quote Link to comment https://forums.phpfreaks.com/topic/249290-please-help-me-with-bug-when-i-get-content-by-tag-name-rss-xml-file/#findComment-1280106 Share on other sites More sharing options...
xyph Posted October 18, 2011 Share Posted October 18, 2011 Why? Are we doing your homework for you? Quote Link to comment https://forums.phpfreaks.com/topic/249290-please-help-me-with-bug-when-i-get-content-by-tag-name-rss-xml-file/#findComment-1280268 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.