pouncer Posted April 7, 2009 Share Posted April 7, 2009 view_rss.php <? $rss_url = "http://www.php.net/news.rss"; if (!$rss_data = @file_get_contents($rss_url)) { echo "<p>No RSS found at $rss_url</p><p>Hmmm thats not meant to happen. RSS Fail!</p>"; } else { $rss_xml = SimpleXML_Load_String($rss_data); $channel_title = $rss_xml->channel->title; $channel_link = $rss_xml->channel->link; foreach ($rss_xml->channel->item as $item) { $item_title = $item->title; $item_link = $item->link; $item_description = $item->description; echo "<h3><a href=\"$item_link\">$item_title</a></h3><p>$item_description</p><p class=\"text_right\"><a href=\"$item_link\">Continue reading $item_title</a></p>\n"; } } ?> Doesn't seem to display nothing for me. but when i try another rss link like $rss_url = "http://www.shanedj.com/blog/feed/rss/"; then it works fine, any ideas whats going wrong guys? Quote Link to comment Share on other sites More sharing options...
Brian W Posted April 7, 2009 Share Posted April 7, 2009 The http://www.shanedj.com/blog/feed/rss/ is working as you expect it... <channel> <item>blah</item> <item>blah</item> <item>blah</item> <item>blah</item> </channel> while http://www.php.net/news.rss is looking like this: <channel> <stuff>de blah</stuff> <stuff>de blah</stuff> <stuff>de blah</stuff> <items>with an s</items> </channel> <item>Looking for this?</item> <item>blah</item> <item>blah</item> item is not a child of channel in the php freaks rss. Try: <?php $rss_url = "http://www.php.net/news.rss"; if (!$rss_data = @file_get_contents($rss_url)) { echo "<p>No RSS found at $rss_url</p><p>Hmmm thats not meant to happen. RSS Fail!</p>"; } else { $rss_xml = SimpleXML_Load_String($rss_data); $channel_title = $rss_xml->channel->title; $channel_link = $rss_xml->channel->link; foreach ($rss_xml->item as $item) { $item_title = $item->title; $item_link = $item->link; $item_description = $item->description; echo "<h3><a href=\"$item_link\">$item_title</a></h3><p>$item_description</p><p class=\"text_right\"><a href=\"$item_link\">Continue reading $item_title</a></p>\n"; } } ?> Quote Link to comment Share on other sites More sharing options...
pouncer Posted April 7, 2009 Author Share Posted April 7, 2009 hmmm i see!! is there a way to make it work for all kinds of rss then? or will the code you posted do that now? Quote Link to comment Share on other sites More sharing options...
pouncer Posted April 7, 2009 Author Share Posted April 7, 2009 Brian I hope you can help me, the code you posted now works fine for: http://www.php.net/news.rss but i also want it to work for the likes of http://www.shanedj.com/blog/feed/rss/ too Quote Link to comment Share on other sites More sharing options...
Brian W Posted April 7, 2009 Share Posted April 7, 2009 I've attached a file that may be of some help to you. Its custom code based on a few snippets I've found around. It will open almost any page but really only effectively handles RSS/XML. It uses the Header tags and indents for importance / tree. EDIT: Made quick change to file [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
Brian W Posted April 7, 2009 Share Posted April 7, 2009 Sorry bro, that code has several issues. Here is a more revised version: [attachment deleted by admin] Quote Link to comment 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.