No need to bookmark this page; your computer will seek it out again on its own.

Display an RSS headline/link using PHP...anywhere!

Date/Time Permalink: 04/10/06 10:01:43 pm
Category: HOWTOs and Guides

Well, been awhile since we had a "hack of the day". Today, after much moaning and pounding of fists (PHP string-handling functions are obtuse!) I have gotten a simple feed parser up on my home page. Along with the link to the blog proper, it now shows the five most recent posts as linked blog headlines.

"Wow, Penguin Pete! How'd you do that?" Well, I'll show you:

echo "Latest Posts:<br>";
echo "<blockquote>";
$feed = file('');
global $item_title;
global $item_link;
global $linkfound;
foreach ($feed as $line)
      echo "<a href=\"" . $item_link . "\">" . $item_title . "</a>";
      echo "<br>";
    if (strlen(stristr($feed[$count],"<title>"))
    elseif (strlen(stristr($feed[$count],"<link>")))
echo "</blockquote>";

Replace the "file('" with the path to whatever RSS feed you want to parse. Paste it in any web page from which you can execute PHP, and you're there! Should work the same for any RSS2.0 feed.

This is my humble 'lil hack for the day. In a similar vein is 'whoo's post in the b2evolution forums Which shows how to add a single entry to your signature box in a forum.

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

suddenly the moon