...

View Full Version : Embedded RSS feed help



Kineas
10-31-2009, 12:46 AM
Hi guys,

At the moment, I've got this code:



<?

$feed_url = "http://www.url.com";

$response = file_get_contents($feed_url);

$xml = simplexml_load_string($response);

foreach($xml->channel->item as $one_item)

$i = 0;
while ($i != 5) {

echo "<TR><TD bgcolor=\"white\"><FONT face=\"Arial\"><BR>"."<a href=".(string)$one_item->link .">".$one_item->title."</A><BR><BR></TD></TR>";
$i++;
if ($i == 5) break;
}
?>

I want it so that only the last 5 entries are shown, but the while loop I put in makes it so that it shows the first entry 5 times.

Any help with this would be great, thanks.

Kineas
10-31-2009, 03:36 AM
*bump*

mlseim
10-31-2009, 04:06 AM
<?

$feed_url = "http://www.url.com";

$response = file_get_contents($feed_url);

$xml = simplexml_load_string($response);

$i = 0;
foreach($xml->channel->item as $one_item){
if($i < 5) {
echo "<TR><TD bgcolor=\"white\"><FONT face=\"Arial\"><BR>"."<a href=".(string)$one_item->link .">".$one_item->title."</A><BR><BR></TD></TR>";
$i++;
}
}
?>

Kineas
10-31-2009, 05:36 AM
Thanks a lot, I knew I hadn't done the loop right lol, works perfectly.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum