Написал скрипт по слиянию нескольких RSS каналов. Привожу полный код (может кому пригодиться):
PHP:
скопировать код в буфер обмена
скопировать код в буфер обмена
- <?PHP
- $number_item = 5;
- $rss_files[] = 'rss.xml';
- $rss_files[] = 'news.xml';
- $rss_files[] = 'sport.xml';
- $rss_files[] = 'articles.xml';
- $rss_files[] = 'mix_all_rss.xml'; // Всегда должен быть последним
- $newxml_head = '<?xml version="1.0" encoding="Windows-1251"?>
- <rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" version="2.0">
- <channel xmlns:cfi="http://www.microsoft.com/schemas/rss/core/2005/internal" cfi:lastdownloaderror="None">
- <title cf:type="text">Статьи моего сайта</title>
- <link>http://мой_сайт</link>
- <description cf:type="text">Новые статьи Моего сайта</description>
- <copyright>Copyright 2010 Мой сайт</copyright>
- <language>ru-ru</language>
- <image>
- <url>мой_сайт/images/banner-100.gif</url>
- <title>Мой сайт</title>
- <link>http://мой_сайт</link>
- <description>мой_сайт</description>
- </image>
- ';
- $newxml_middle = '
- <docs>http://blogs.law.harvard.edu/tech/rss</docs>
- <atom:link href="http://мой_сайт/rss/mix_all_rss.xml" rel="self" type="application/rss+xml"/>
- ';
- $newxml_end = '
- </channel>
- </rss>';
- foreach ( $rss_files as $key=>$file_name )
- {
- $domdocument[$key] = new domDocument ( '1.0', 'Windows-1251');
- $domdocument[$key]->preserveWhiteSpace = false;
- $domdocument[$key]->load( $file_name );
- $channel[$key] = $domdocument[$key]->documentElement->firstChild;
- $channel_items[$key] = $channel[$key]->getElementsByTagName( 'item' );
- $lastpubdate[$key] = strtotime( $channel_items[$key]->item(0)->getElementsByTagName( 'pubDate' )->item(0)->nodeValue );
- }
- if ( $time_mix_file >= $time_last_pub )
- {
- $mix_file_domdocument->encoding = 'Windows-1251';
- $mix_file_domdocument->formatOutput = true;
- echo $mix_file_domdocument->saveXML();
- }
- else
- {
- foreach ( $domdocument as $key=>$domdoc )
- {
- $domdocument[$key]->encoding = 'Windows-1251';
- $domdocument[$key]->formatOutput = true;
- for ($i=0; $i<$number_item; $i++)
- {
- $date = strtotime( $channel_items[$key]->item($i)->getElementsByTagName( 'pubDate' )->item(0)->nodeValue );
- $items[$date] = iconv( 'UTF-8', 'Windows-1251', $domdocument[$key]->saveXML( $channel_items[$key]->item($i) ) );
- }
- }
- echo $newxml;
- }
- ?>