Jump to content

does anyone have a simple RSS code that works


billy2shoe

Recommended Posts

does anyone have any simple RSS code that works .. i would like to learn about this...

(please dont post a site..as all the sites i find with code seem not to work????)

http://www.phpit.net/article/screenscrap-rss/2/

 

what would be awesome is someone that has an example that WORKS.. ie returns something when u run it

this snippet of code will read and parse the RSS feed XML file:

 

<?php

// The @ is to supress the function´ errors

$newsfeed = 'http://url/to/file.xml';

$fp = @fopen($newsfeed, 'r');
while(!feof($fp)){
  $row .= @fgets($fp, 4096);
}
@fclose($fp);

if( eregi('<item>(.*)</item>', $row, $rowitem ) ) {
$item = explode('<item>', $rowitem[0]);

for( $i = 0; $i < count($item) - 1; $i   ) {

  eregi('<title>(.*)</title>', $item[$i 1], $title );
  eregi('<url>(.*)</url>', $item[$i 1], $url );
  eregi('<categorie>(.*)</categorie>', $item[$i 1], $categorie);

  echo '<a href="' . $url[1] . '">' . $title[1] . '</a> - ' . $categorie[1] . '<br />';

}
}

?>

It depends on the feed. Imagine this. The 'feeder' site publishes an XML file that you pull into your site using the snippet of code. The XML file contains instructions to parse the last 25 tutorials added to their database which is added to daily by various authors, let's say. So, no matter what, each day as long as there are new tutorials published they will be fed to your site and displayed. New content. Simple.

You could have the XML set for the last 100 if you want. Just have to make sure you have room for them on your page. The other key is, you can use that same snippet in dozens of locations throughout your site (like category pages) and just have it call a different XML file relative to the topic you've placed it in.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.