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? Link to comment https://forums.phpfreaks.com/topic/152988-rss-feed-problem/ 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"; } } ?> Link to comment https://forums.phpfreaks.com/topic/152988-rss-feed-problem/#findComment-803598 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? Link to comment https://forums.phpfreaks.com/topic/152988-rss-feed-problem/#findComment-803909 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 Link to comment https://forums.phpfreaks.com/topic/152988-rss-feed-problem/#findComment-803934 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] Link to comment https://forums.phpfreaks.com/topic/152988-rss-feed-problem/#findComment-804012 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] Link to comment https://forums.phpfreaks.com/topic/152988-rss-feed-problem/#findComment-804035 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.