Manny Posted July 12, 2009 Share Posted July 12, 2009 First, take a look at the following website:http://www.toffeeweb.com/Underneath the navigation on the right hand side, they have some latest news stories from other websites flashing on and off the screen. I'm guessing they get these headlines from RSS feeds, but how would I go about getting something similar to what this website is using?Here are some of the feeds I would use:http://www.skysports.com/rss/0,20514,11672,00.xmlhttp://www.goal.com/en/feeds/team-news?id=100&fmt=rsshttp://www.theboltonnews.co.uk/wanderers/wanderersnews/rss/ Link to comment Share on other sites More sharing options...
Synook Posted July 13, 2009 Share Posted July 13, 2009 http://www.aspektas.com/blog/parsing-rss-feeds-using-php Link to comment Share on other sites More sharing options...
Manny Posted July 14, 2009 Author Share Posted July 14, 2009 Ok. I found that link very useful, but you can only use one feed at once without storing the feeds in variables, like I've done with the code below: <?phpdate_default_timezone_set('Europe/London');$selectfeed=rand(1, 3);$rss = new DOMDocument();if($selectfeed==1){ $name = "Sky Sports"; $rss->load("http://www.skysports.com/rss/0,20514,11672,00.xml"); } if($selectfeed==2){ $name = "BBC Sport"; $rss->load("http://newsrss.bbc.co.uk/rss/sportonline_uk_edition/football/teams/b/bolton_wanderers/rss.xml"); } if($selectfeed==3){ $name = "Vital Bolton"; $rss->load("http://www.vitalfootball.co.uk/rss.asp?t={4FC2D463-F1C2-4318-9292-2B1CBC8A5406}"); }$items = $rss->getElementsByTagName("item");foreach ($items as $item) { $title = $item->getElementsByTagName("title")->item(0)->nodeValue; $link = $item->getElementsByTagName("link")->item(0)->nodeValue; $time = $item->getElementsByTagName("pubDate")->item(0)->nodeValue; $time = date("j M g:i a", strtotime($time)); //DISPLAY TOP STORY if($topstories < 1) { print "<a href=\"$link\" target=\"_blank\">$title</a> - $name - $time<br /> \n"; } $topstories += 1;}?> Would I be able to get news from all these feeds and have them merge into one. With the latest stories being based at the top, as the most recent.This website is something of an example, getting stories from a collection of websites:http://www.newsnow.co.uk/h/Sport/Football/...olton+Wanderers Link to comment Share on other sites More sharing options...
Synook Posted July 15, 2009 Share Posted July 15, 2009 Instead of immediately outputting the RSS items, you could store them in a multidimensional array, e.g. $time = $item->getElementsByTagName("pubDate")->item(0)->nodeValue; $stories[$time]["title"] = $item->getElementsByTagName("title")->item(0)->nodeValue; $stories[$time]["link"] = link = $item->getElementsByTagName("link")->item(0)->nodeValue; Then you can use krsort() to sort the amalgamated items according to time, before looping through the array and printing everything out. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.