同じ Web サイトに 4 つの RSS フィードがあります。私の関数は次のようになります。
//-- get_rss ----------------------------------------------------------------------------------
// Returns the RSS feed in LI elements
// @param $url (feed url) is recieved from page template
// @param $lang (possibillity to declare language if available) is recieved from page template
//---------------------------------------------------------------------------------------------
function get_rss($url, $lang, $articles) {
$rss = new rss_php;
$rss->load($url);
$items = $rss->getItems();
// Sets the maximum items to be listed
$max_items = $articles;
$count = 0;
$html = '';
// Translates months to swedish
foreach($items as $index => $item) {
$pubdateForeignString = substr($item['pubDate'], 4);
$pubdateEnglishString = str_replace(array('maj', 'okt'), array('may', 'oct'), $pubdateForeignString);
$pubdate = date("Y-m-d", strtotime($pubdateEnglishString));
$html .= '
<ul class="rssList">
<li class="itemTitle"><a href="'.$item['link'].'" title="'.$item['title'].'" rel="external"><h2>'.$item['title'].'</h2></a></li>
<li class="itemText">'.$item['description'].'</li>
<li class="itemLink"><a href="'.$item['link'].'" title="'.$item['title'].'" rel="external" class="readmore">Läs mer</a><em>Publicerad: '.$pubdate.'</em></li>
</ul>';
$count++; //Increase the value of the count by 1
if($count==$max_items) break; //Break the loop is count is equal to the max_loop
}
echo $html;
}
2 つの RSS フィードには pubDate があり、他の 2 つには dc:date があります。したがって、pubDate を dc:date に変更すると 2 が機能し、他のものは「1970-01-01」と表示され、dc:date を pubDate に変更すると、同じ結果が得られますが、逆になります。
今私の質問は、両方のタイプを実行できるように関数を「編集」する最も簡単な方法は何ですか?