// Feeds to parse $google = parse_feed('http://news.google.co.uk/news?um=1&ned=uk&hl=en&q=football&output=rss'); $bbc = parse_feed('http://newsrss.bbc.co.uk/rss/sportonline_uk_edition/front_page/rss.xml');
// Array to store feed data in $merged = array();
// Add feed 1 data to array foreach($google as $data) : $merged[] = $data; endforeach;
// Add feed 2 data to array foreach($bbc as $data) : $merged[] = $data; endforeach;
// Sort the data with volume descending, edition ascending // Add $data as the last parameter, to sort by the common key foreach ($merged as $key => $row) { $pubdate[$key] = $row['pubDate']; }
I've amended my code a little now - It will display items grouped into how old they are, IE, last hour, 1-2 hours old, 2-4 hours old and over 4 hours old.
PHP Code:
<?php
// Convert date
function get_date($date)
{
return date('Y-m-d H:i:s', strtotime($date));
}
// Convert date to timestamp
function convert_to_timestamp($date)
{
return strtotime($date);
}
// Feeds to parse
$google = parse_feed('http://news.google.co.uk/news?um=1&ned=uk&hl=en&q=football&output=rss');
$bbc = parse_feed('http://newsrss.bbc.co.uk/rss/sportonline_uk_edition/front_page/rss.xml');
// Array to store feed data in
$merged = array();
// Add feed 1 data to array
foreach($google as $data) :
$merged[] = $data;
endforeach;
// Add feed 2 data to array
foreach($bbc as $data) :
$merged[] = $data;
endforeach;
// Sort the data with volume descending, edition ascending
// Add $data as the last parameter, to sort by the common key
foreach ($merged as $key => $row) {
$pubdate[$key] = $row['pubDate'];
}
foreach ($feeds as $feed) {
$merged[] = parse_feed($feed);
}
I've had to change the above to
PHP Code:
foreach ($feeds as $feed) :
$fe = parse_feed($feed);
foreach ($fe as $f):
$merged[] = $f;
endforeach;
endforeach;
As the code you suggested wasn't working.
As for creating an array of feeds - that's a good idea - I actually was going to do that in the future - as the feed urls are going to be pulled from a database once I've got the basic concept down.
Seems to be working fine now.
Full code is here -
PHP Code:
<?php
# Set default timezone
date_default_timezone_set('Europe/London');
ini_set('display_errors', 1);
error_reporting(E_ALL|E_STRICT);
// Convert date
function get_date($date)
{
return date('Y-m-d H:i:s', strtotime($date));
}
// Convert date to timestamp
function convert_to_timestamp($date)
{
return strtotime($date);
}
foreach ($feeds as $feed) :
$fe = parse_feed($feed);
foreach ($fe as $f):
$merged[] = $f;
endforeach;
endforeach;
// Sort the data with volume descending, edition ascending
// Add $data as the last parameter, to sort by the common key
foreach ($merged as $key => $row) {
$pubdate[$key] = $row['pubDate'];
}
Bookmarks