Mourning the loss of our friend, WhitPhil.
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
 
Web Design & Development
Tag Cloud
access audio blue screen boot bsod connection crash dell desktop driver dvd email error excel excel 2003 firefox hard drive hardware hdmi hijackthis internet keyboard laptop malware monitor motherboard network networking outlook problem ram recovery router screen slow sound spyware tdlwsp.dll trojan upgrade vba video virus vista vundo windows windows 7 windows vista windows xp wireless
Search
Search for:
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
PHP embedded RSS feed

Tip: Click here to scan for System Errors and Optimize PC performance
[ Sponsored Link ]

 
Thread Tools
kineas's Avatar
Computer Specs
Junior Member with 14 posts.
 
Join Date: Jun 2008
30-Oct-2009, 06:28 PM #1
PHP embedded RSS feed
Hi,

So far I have got this code:

PHP 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 
$one_item->title."<BR>";
  
$i++;
  if (
$i == 5) break;
  }


?>
I want it so that it show's the last 5 entries, but that's the best I could do and it's showing the first entry 5 times.

Any help would be great, thanks.

Last edited by kineas : 30-Oct-2009 07:42 PM.
maneetpuri's Avatar
Member with 67 posts.
 
Join Date: Oct 2008
31-Oct-2009, 04:14 AM #2
Hi,

If you can first count the number of reco0rds in this file and then set the array pointer to minus 5 position from the total number of records and run the while loop, that should solve your problem.

Hope this helps.

Cheers,
kineas's Avatar
Computer Specs
Junior Member with 14 posts.
 
Join Date: Jun 2008
31-Oct-2009, 05:29 AM #3
Well, I already posted on a different forum because I got bored of waiting, and a guy gave me the exact code I need:

PHP Code:
<?

  $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><BR>"."<a href=".(string)$one_item->link .">".$one_item->title."</A><BR><BR></TD></TR>";
   
$i++;
   }
}
?>
It's what I thought, I had done the loop wrong.
Reply Bookmark and Share

Smart Search

Find your solution!



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.

Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 03:19 AM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.
Powered by Cermak Technologies, Inc.