Reset to a default $var... Can't get my RSS news script to w

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
OTY
Forum Newbie
Posts: 1
Joined: Sat Nov 05, 2005 2:57 pm

Reset to a default $var... Can't get my RSS news script to w

Post by OTY »

Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


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:

Code: Select all

<?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){

[b]echo "There is no news on $section."; // Would I tell it to reset to $topic here?[/b]
}

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("&apos;", "'", $title[$counter][1]);

$description[$counter][1] = str_replace("&", "&", $description[$counter][1]);
$description[$counter][1] = str_replace("&apos;", "'", $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


Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Post Reply