Я только что сделал код из разных кодов, чтобы проанализировать мои xml rss и объединить их. Со временем, но теперь я не могу добавить название канала, какая-нибудь помощь?
Вот рабочий код, может быть кому-то полезен, просто титульный канал не отображается с каналом lo go в качестве размера ico, я хочу его после отметки времени, и код будет идеальным ¨!
<?php
class Feed_Miro
{
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 merge_feeds(){
$temp = array();
foreach ( $this->data as $item )
{
if ( !in_array($item->link, $this->links($temp)) )
{
$temp[] = $item;
}
} $this->data = $temp;
}
private function links( array $items ){
$links = array();
foreach ( $items as $item )
{
$links[] = $item->link;
}
return $links;
}
}
/*********
add urls
*********/
$urls = array('https://www.francetvinfo.fr/titres.rss', 'http://www.lefigaro.fr/rss/figaro_actualites.xml', 'https://fr.sputniknews.com/export/rss2/archive/index.xml' );
try
{
$feeds = new Feed_Miro;
$feeds->addFeeds( $urls );
$feeds->grabRss();
$feeds->merge_feeds();
}
catch ( exception $e )
{
die( $e->getMessage() );
}
// test from here
$data = array();
$data = $feeds -> data;
usort($data, function($a,$b){
return strtotime($b->pubDate) - strtotime($a->pubDate);
});
foreach ( $data as $item ) :
//foreach ( $feeds->data as $item ) :
extract( (array) $item );
$pubDate = $item->pubDate;
$pubDate = strftime("%d-%m-%Y %H:%M:%S", strtotime($pubDate));
?>
<div class="span4 profile">
<h4 class="feed-item-title"><a href="<?php echo $link; ?>"><?php echo $title; ?></a></h4>
<table class="trss">
<tbody>
<tr>
<td class="frss"><p class="profile-description"><?php echo $description; ?> <a href="<?php echo $link ?>" target="_blank">En savoir plus... - </a><?php echo $pubDate; ?></p></td>
<td class="frss"><?php echo "<img class=\"rsspic\" src=\"" . (string)$item->enclosure['url'][0] . "\" height=\"150\" width=\"150\">";?> </td>
</tr>
</tbody>
</table>
</div>
<?php endforeach; ?>```