Member
From: Fort Worth, TX
Registered: 2006-04-05
Posts: 15
I've been thanked 0 times.
Offline
I believe that code is the one that iterates through the entries of the rss for the limit you specify.
I'm sure there is a variable that links the counter to the entry id. If you see something like $description[$counter] set it to [$counter-1].
The only problem with that is that it's going to mess up the feeds that are correct. So what you'd need to do, until there is a verification code written, is to have two different readers, one that works for rss 2.0 and one that works for 0.9....the 2.0 one being the $counter-1 change. And then just test them all on the original, and you'll know to use the 2.0 reader for that feed if it does not display properly.
Member
From: Sydney, Australia
Registered: 2004-10-23
Posts: 593
I've been thanked 0 times.
Offline
SR wrote:
As a point of clarification (and not to sound like a snob), but there is a huge difference between java and javascript. Just for future reference...
I actually thought to myself, after submitting the post, "Should I change those to 'javascript', then I thought, "nahh, people will know what I mean.... surely..:/
Thanks for not being as lazy as I, SR... 
Wiz
I cried because I had no shoes - until I saw a man who had no feet...
TA,
I know you are getting a lot of people telling you to do a lot of things, so I'll just throw this out there. I went through and looked your site and was, quite frankly, stumped as to why the include was not working for you. I did create a workaround with the script - I made a few changes to the script just to get it to work. Its not sexy, but I got it to work on my system...
If you do want to give it a try, don't delete the other stuff in case this doesn't work for you.
This is the reader script - name it something like reader2.php
Code:
<?php
//
// ScarySoftware RSS parser
// Copyright (c) 2006 Scary Software
// ( Generates HTML from a RSS feeds )
//
// Licensed Under the Gnu Public License
//
// Here are the feeds - you can add to them or change them
$RSSFEEDS = array(
0 => "http://www.site-reference.com/xml.php?c=all",
1 => "http://rss.cnn.com/rss/cnn_topstories.rss",
2 => "http://rss.slashdot.org/Slashdot/slashdot",
3 => "http://www.site-reference.com/xml.php?c=all",
4 => "http://rss.cnn.com/rss/cnn_topstories.rss",
5 => "http://rss.slashdot.org/Slashdot/slashdot",
);
//
// Makes a pretty HTML page bit from the title,
// description and link
//
function FormatRow($title, $description, $link) {
return <<<HTML
<!-- RSS FEED ENTRY -->
<p class="feed_title">$title</p>
<p class="feed_description">$description</p>
<a class="feed_link" href="$link" rel="nofollow" target="_blank">Read more...</a>
<p> </p>
<hr size=1>
<!-- END OF RSS FEED ENTRY -->
HTML;
}
foreach($RSSFEEDS as $feedid => $feed){
// we'll buffer the output
ob_start();
// Now we make sure that we have a feed selected to work with
if (!isset($feedid)) $feedid = 0;
$rss_url = $RSSFEEDS[$feedid];
// Server friendly page cache
$ttl = 60*60;// 60 secs/min for 60 minutes = 1 hour(360 secs)
$cachefilename = md5($rss_url);
if (file_exists($cachefilename) && (time() - $ttl < filemtime($cachefilename))) {
// We recently did the work, so we'll save bandwidth by not doing it again
include($cachefilename);
exit();
}
// Now we read the feed
$rss_feed = @file_get_contents($rss_url);
// Now we replace a few things that may cause problems later
$rss_feed = str_replace("<![CDATA[", "", $rss_feed);
$rss_feed = str_replace("]]>", "", $rss_feed);
$rss_feed = str_replace("\n", "", $rss_feed);
// Now we get the nodes that we're interested in
preg_match_all('#<title>(.*?)</title>#', $rss_feed, $title, PREG_SET_ORDER);
preg_match_all('#<link>(.*?)</link>#', $rss_feed, $link, PREG_SET_ORDER);
preg_match_all('#<description>(.*?)</description>#', $rss_feed, $description, PREG_SET_ORDER);
//
// Now that the RSS/XML is parsed.. Lets Make HTML !
//
// If there is not at least one title, then the feed was empty
// it happens sometimes, so lets be prepared and do something
// reasonable
if(count($title) <= 1)
{
echo "No news at present, please check back later.<br><br>";
}
else
{
// OK Here we go, this is the fun part
// Well do up the top 3 entries from the feed
for ($counter = 1; $counter <= 3; $counter++ )
{
// We do a reality check to make sure there is something we can show
if(!empty($title[$counter][1]))
{
// Then we'll make a good faith effort to make the title
// valid HTML
$title[$counter][1] = str_replace("&", "&", $title[$counter][1]);
$title[$counter][1] = str_replace("'", "'", $title[$counter][1]);
// The description often has encoded HTML entities in it, and
// we probably don't want these, so we'll decode them
$description[$counter][1] = html_entity_decode( $description[$counter][1]);
// Now we make a pretty page bit from the data we retrieved from
// the RSS feed. Remember the function FormatRow from the
// beginning of the program ? Here we put it to use.
$row = FormatRow($title[$counter][1],$description[$counter][1],$link[$counter][1]);
// And now we'll output the new page bit!
echo $row;
}
}
}
// Finally we'll save a copy of the pretty HTML we just created
// so that we can skip most of the work next time
//$fp = fopen($cachefilename, 'w');
//fwrite($fp, ob_get_contents());
//fclose($fp);
// All Finished!
ob_end_flush(); // Send the output to the browser
}
?>
Now create your test page, name it something like test2.php. Assuming you have it in the same directory as the reader script, use this PHP code:
Code:
<?php include("reader2.php"); ?>Today's article: A Unique Look at Adwords Advertising
SR,
Thanks for your last post ave tried it and it works fine except that it shows the feeds twice i.e
1. SR Feeds
2. CNN
3. Slashdot
then it repeats the feeds again in that order...check it out http://www.simbahosting.net/news2.php
What do i need to change to show the feeds once.
Thanks for the excellent work ave been racking my head over this script for many adays! 
Kwezi,
It shows feeds twice because it has the same set of feeds twice. This is the code as it stands right now:
Code:
// Here are the feeds - you can add to them or change them
$RSSFEEDS = array(
0 => "http://www.site-reference.com/xml.php?c=all",
1 => "http://rss.cnn.com/rss/cnn_topstories.rss",
2 => "http://rss.slashdot.org/Slashdot/slashdot",
3 => "http://www.site-reference.com/xml.php?c=all",
4 => "http://rss.cnn.com/rss/cnn_topstories.rss",
5 => "http://rss.slashdot.org/Slashdot/slashdot",
);
If you want to display each feed just once, then change that to:
Code:
// Here are the feeds - you can add to them or change them
$RSSFEEDS = array(
0 => "http://www.site-reference.com/xml.php?c=all",
1 => "http://rss.cnn.com/rss/cnn_topstories.rss",
2 => "http://rss.slashdot.org/Slashdot/slashdot",
);
Today's article: A Unique Look at Adwords Advertising
SiteReference wrote:
Kwezi,
It shows feeds twice because it has the same set of feeds twice.
Oh gees i thnk it the tea i took this morning hadn't even looked at that SR it works JUST fine.....eeer i think i'll go get a cup of coffee...should wake up my mind: lol:
Thanks SR made my day........
Member
From: Pell City, Alabama USA
Registered: 2004-11-17
Posts: 2084
I've been thanked 5 times.
Offline
Hey Skip - the file name is case sensitive
you've got reader2.php in your test page's include, but the file is named Reader2.php
Notice the capital R ?
Change one or the other of them so that they match
TombOfTheMutilated.NET - Destroying The Minds of America's Youth Since 2001
travelagent wrote:
kwezi -- yes it is -- go back to the bottom of page 6 in this section and see the code SR gave me for the testpage.
TA seems you have it working congrats....
travelagent wrote:
DOH! -- I went right past that ... now, it all works properly ... THANKS, SR & Mutilated!
Woooo hoooo!!! 




Today's article: A Unique Look at Adwords Advertising
Administrator
From: you know you want a caricature
Registered: 2004-11-08
Posts: 3509
I've been thanked 37 times.
Offline
here is another option - based on CGI, developed by a fellow Aussie
Member
From: Fort Worth, TX
Registered: 2006-04-05
Posts: 15
I've been thanked 0 times.
Offline
:/ It would have been just as easy for me to ask TA what feeds he wanted, and write the code for him, but I wanted him to learn how to do it - so that he would know what was going on. There wasn't anything wrong with the post and codes I made - they were straight from working files. (Maybe it was "packet loss" in the data transmitted from the eyes to brain to fingers to computer
)
Oh well. Glad it works now.
Member
From: Pell City, Alabama USA
Registered: 2004-11-17
Posts: 2084
I've been thanked 5 times.
Offline
eltaito wrote:
thanks Neo....thats pretty much what I've been looking at too......I'm just not sure where in the PHP the starting point is defined...i see this code:
Code:
for ($counter = 1; $counter <= $howmany; $counter++ )so I figure this means it is searching for the first title/descrip/link and then going up in increments of 1 until it reaches the number I defined in the call defined in my html document.......I guess I wonder if there is a way that I can set the description starting point back one (its the descriptions that appear to be off)..but then if I did that wouldn't that mess up the newsvine feed?......maybe Mutilated1 will know......I have to say though that I love this code.....I like it a whole lot more than the Javascript methods I see out there...but I guess I'm getting off topic here....I'm going to keep blindly tinkering (its kinda fun).....I'll check back later to see if anybody has any ideas....
eltaito - the mismatched descriptions in the RSS feed I've noticed before, somehow it only happens with certain feeds though. I'm not exactly sure why it occurs, but I suspect what is happening is that the feed itself has a title and URL but not a description, so then the preg_match_all()s that parse out the pieces come up with one too few descriptions, and thus the elements in the array $description are all offset by one.
Like I was saying it does not happen on every feed though.
If you can point me to a feed that causes the problem, I will see if I can find a solution.
TombOfTheMutilated.NET - Destroying The Minds of America's Youth Since 2001
Member
From: Wilmington, N.C.
Registered: 2006-04-05
Posts: 14
I've been thanked 0 times.
Offline
hey Mutilated1..thanks for the reply..these are the two feeds that are giving me the trouble:
http://newsrss.bbc.co.uk/rss/newsonline … ge/rss.xml
http://wired.com/rss/index.xml
honestly I don't really care about the wired one but the BBC news I'd like to get working if possible.
Its a funny time to learn to swim when you start to drown.
Member
From: Wilmington, N.C.
Registered: 2006-04-05
Posts: 14
I've been thanked 0 times.
Offline
oh and here is the link to my test feed page again if you want to see what the feed looks like
http://eltaito.com/news.php
Its a funny time to learn to swim when you start to drown.
Member
From: Pell City, Alabama USA
Registered: 2004-11-17
Posts: 2084
I've been thanked 5 times.
Offline
Your test page is looking good. I'm pretty sure I know whats going wrong, but its going to be a few hours before I have time to sit down and try to work out a solution.
I'll try and get back to you late tonight or early morning though.
TombOfTheMutilated.NET - Destroying The Minds of America's Youth Since 2001
Member
From: Wilmington, N.C.
Registered: 2006-04-05
Posts: 14
I've been thanked 0 times.
Offline
no problemo.....thanks for looking into it!
Its a funny time to learn to swim when you start to drown.
Member
From: Pell City, Alabama USA
Registered: 2004-11-17
Posts: 2084
I've been thanked 5 times.
Offline
OK, I've fixed the problem and the code samples are updated.
If you notice that your description seems to be out of sync with the title on some of your feeds, then either get a new copy of the code off of my site, or make this change to your reader.
Find the section of code that looks like this:
Code:
// Now we replace a few things that may cause problems later
$rss_feed = str_replace("<![CDATA[", "", $rss_feed);
$rss_feed = str_replace("]]>", "", $rss_feed);
$rss_feed = str_replace("\n", "", $rss_feed);
Immediately after that add this.
Code:
// If there is an image node remove it, we aren't going to use
// it anyway and it often contains a <title> and <link>
// that we don't want to match on later.
$rss_feed = preg_replace('#<image>(.*?)</image>#', '', $rss_feed, 1 );
Sorry for the inconvience, if you notice anything else please let me know, I always want to make it better if I can.
TombOfTheMutilated.NET - Destroying The Minds of America's Youth Since 2001
Member
From: Wilmington, N.C.
Registered: 2006-04-05
Posts: 14
I've been thanked 0 times.
Offline
awesome...works like a charm....thank you Mutilated!!!! And thanks again for sharing this code..have been looking for something like this for ages
Its a funny time to learn to swim when you start to drown.
Member
From: Pell City, Alabama USA
Registered: 2004-11-17
Posts: 2084
I've been thanked 5 times.
Offline
Thanks for the kind comments. I'm glad you find it usefull. I had a good time writing it, and once you get it installed and working its actually very easy to put a feed pretty much anywhere you like.
TombOfTheMutilated.NET - Destroying The Minds of America's Youth Since 2001
Member
From: Pell City, Alabama USA
Registered: 2004-11-17
Posts: 2084
I've been thanked 5 times.
Offline
travelagent wrote:
Don't pat yourselves on the back just yet -- Google may be issuing all of us a cease-and-desist order for using their RSS Feeds
By any chance did you notice the date on that article ? ha ha ha
I wouldn't worry about it
Besides he was scraping google search results and creating/publishing an RSS feed from it, What you're doing is using the RSS feed that google themselves publish. I doubt they're going to try and stop you, and if they did try and stop you, they'd just deny you access to the feed rather than issue a cease and desist order. Why go to court with you when one of their programmers can turn off your access to the feed in a couple of minutes when a lawyer is going to charge them hundreds per hour for weeks ?
Doesn't make much sense.
Besides that - look at the date on the article. Its a joke.
TombOfTheMutilated.NET - Destroying The Minds of America's Youth Since 2001
| Never |


