Hi, I'm trying to write an RSS news script for my site so that it will pull relevant news related to the section of the site... but the thing is some of the sections have no news... so I would like it to then pull news from the main topic from the site. I'm not sure how to get it to do this though. I've tried everything.
Right now I just have it displaying: echo "There is no news on $section."; if there is no news... Instead of displaying that I would like it to pull news using the variable $topic if it can't find any news from that section...
Here is the script:
<?php
$filename = "http://search.msn.com/news/results.aspx?q=$section&format=rss&FORM=RSNR";
$feed = implode('', file($filename));
preg_match_all('#<title>(.?)</title>#', $feed, $title, PREG_SET_ORDER);
preg_match_all('#<link>(.?)</link>#', $feed, $link, PREG_SET_ORDER);
preg_match_all('#<description>(.*?)</description>#', $feed, $description, PREG_SET_ORDER);
$nr = count($title);
if($nr == 1){
echo "There is no news on $section."; // Would I tell it to reset to $topic here?
}
elseif($nr > 1){
for ($counter = 1; $counter < 11; $counter++ ){
if(empty($title[$counter][1])){
echo "";
}
elseif(!empty($title[$counter][1])){
$title[$counter][1] = str_replace("&", "&", $title[$counter][1]);
$title[$counter][1] = str_replace("'", "'", $title[$counter][1]);
$description[$counter][1] = str_replace("&", "&", $description[$counter][1]);
$description[$counter][1] = str_replace("'", "'", $description[$counter][1]);
echo "<p>".$title[$counter][1]."</p>";
echo "<p>".$description[$counter][1]."</p>";
echo "<a href=\"".$link[$counter][1]."\">Read more</a><br>";
}
}
}
?>
Thx