1) Get multiple feeds & merge them
2) Convert item dates {both RSS 1.0 and 2.0 to unix time format}
3) Sort items
4) Publish results...
I can't say that I have a good command of PHP, but I know couple of different programming languages, so I found some codes on the net regarding how to do this, modified and merged them them. And, of course, it failed. There's a problem with the code... Could you guys take a look at it... I will appreciate a looot. Here's the code that I come up with:
Here's what I'm trying to do:
1) Get multiple feeds & merge them
2) Convert item dates {both RSS 1.0 and 2.0 to unix time format}
3) Sort items
4) Publish results...
I can't say that I have a good command of PHP, but I know couple of different programming languages, so I found some codes on the net regarding how to do this, modified and merged them them. And, of course, it failed. There's a problem with the code... Could you guys take a look at it... I will appreciate a looot. Here's the code that I come up with:
<?php
require_once('magpierss/rss_fetch.inc');
$urls = array('http://www.businessweek.com/rss/brandequity.rss', 'http://feeds.feedburner.com/marketingvox/rss');
$items = array();
foreach ( $urls as $url ) {
$rss = fetch_rss($url);
if (!$rss) continue;
$items = array_merge($items, $rss->items);
}
function displayUnixTimestamp($item) {
$rss_2_date = $item['pubdate'];
$rss_1_date = $item['dc']['date'];
$atom_date = $item['issued'];
if ($atom_date != "") $date = parse_w3cdtf($atom_date);
if ($rss_1_date != "") $date = parse_w3cdtf($rss_1_date);
if (strlen($rss_1_date) == 10) $date = strtotime($rss_1_date);
if ($rss_2_date != "") $date = strtotime($rss_2_date);
if ($date == "") $date = time();
return $date;
}
function date_cmp($a, $b) {
if ($a['displayUnixTimestamp'] == $b['displayUnixTimestamp'] ) {
return 0;
}
return ($a['displayUnixTimestamp'] > $b['displayUnixTimestamp'] ) ? -1 : 1;
}
usort($items, 'date_cmp');
for($i=0;$i<10;$i++) {
$item = $items[$i];
$href = $item['link'];
$title = $item['title'];
$desc = $item['description'];
if (strlen($desc) >= 1000)
{
$desc = substr($desc,0,499)."...";
}
echo '<span class="h1nonh1lite"><br /><br /></span><strong class="bodyRED"><a href='. $href . ' class="bodyRED">' . $title . '</a><br /></strong>';
if($desc)
echo '<span class="body">' . $desc . '<br /></span>';
if ($date != '')
{
echo '<span class="h1nonh1lite">Publish Date: ' . $date . '</span>';
}
}
?>