Consider having 4 different RSS news feeds URL's
$urls[0]['news'] = "url1";
$urls[1]['news'] = "url2";
$urls[2]['news'] = "url3";
$urls[3]['news'] = "url4";
The following function should get 4 news titles from each of the url's
function getRssFeeds($urls,$type){
//Prepare XML objects
$xmls[$type] = array();
//Prepare item objects
$items[$type] = array();
//Prepare news titles/links arrays
$article_titles[$type] = array();
$encoded_titles[$type] = array();
$article_links[$type] = array();
//Fill XML objects
for($i=0; $i<4; $i++){
$xmls[$i][$type] = simplexml_load_file($urls[$i][$type]);
//Prepare news items
$items[$i][$type] = $xmls[$i][$type]->channel->item;
for($i=0; $i<4; $i++){
$article_titles[$i][$type] = $items[$i][$type]->title;
$encoded_titles[$i][$type] = iconv("UTF-8","windows-1251",$article_titles[$i][$type]);
}
//$article_links[$type][$i] = $items[$type][$i]->link;
}
return $encoded_titles;
}
After using the following to get the values:
type='';
function printRssFeed($urls,$type){
$titles = getRssFeeds($urls,$type);
foreach($titles as $title)
{
echo $title[$type]."<hr/>";
}
}
I get undefined offset error. If I remove the inner for loop of the getRssFeeds()
function I get only 1 new title from each URL.