Hello, I’m hoping someone can help me..I’m working on something that aggregates several RSS feeds and displays them as one list of news, unfortunately I have tried a couple of different methods of ordering the $pubDate ascending, and wondered if anyone had any ideas of how to order by pubDate?
[CODE]<?php
$formal = array();
…….
class Feed_Amalgamator
{
public $urls = array();
public $data = array();
public function addFeeds( array $feeds )
{
$this->urls = array_merge( $this->urls, array_values($feeds) );
}
public function grabRss()
{
foreach ( $this->urls as $feed )
{
$data = @new SimpleXMLElement( $feed, 0, true );
if ( !$data )
throw new Exception( ‘Could not load: ‘ . $feed );
foreach ( $data->channel->item as $item )
{
$this->data[] = $item;
}
}
}
public function amalgamate()
{
shuffle( $this->data );
$temp = array();
foreach ( $this->data as $item )
{
if ( !in_array($item->link, $this->links($temp)) )
{
$temp[] = $item;
}
}
$this->data = $temp;
shuffle( $this->data );
}
private function links( array $items )
{
$links = array();
foreach ( $items as $item )
{
$links[] = $item->link;
}
return $links;
}
}
//this is where the arrays are constructed
try
{
$feeds = new Feed_Amalgamator;
$feeds->addFeeds( $formal );
$feeds->grabRss();
$feeds->amalgamate();
}
catch ( exception $e )
{
die( $e->getMessage() );
}
foreach ( $feeds->data as $item ) :
extract( (array) $item );
?>
<h2 class=”ui-bar-a”><a href=”<?php echo $link; ?>”><?php echo $title; ?></a></h2>
<p><?php echo $description; ?></p>
<p><em><?php echo $pubDate; ?></em></p>
<p><?php endforeach; ?></p>