Jump to content

XML how to not display all tags


xpersa

Recommended Posts

Hello,

 

I would like to ask you how is possible to display let's say first 10 results from a XML file. Here is a piece of my code that i use to display only the title and link to the article on uefa.com but i dont know how to get only first 10 result and not the whole file

 

      <?php

$rss_file = "http://www.uefa.com/rssfeed/news/rss.xml";
$rss_feed = simplexml_load_file( $rss_file );

foreach( $rss_feed->channel->item as $item  ) {
echo"<a title='$item->title' href='$item->link'> $item->title</a>";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/207293-xml-how-to-not-display-all-tags/
Share on other sites

  <?php

$rss_file = "http://www.uefa.com/rssfeed/news/rss.xml";
$rss_feed = simplexml_load_file( $rss_file );
$count=0;

foreach( $rss_feed->channel->item as $item  ) {
while($count<10){
echo"<a title='$item->title' href='$item->link'> $item->title</a>";
$count++;
}
}
?>

of course it does! doh!

  <?php

$rss_file = "http://www.uefa.com/rssfeed/news/rss.xml";
$rss_feed = simplexml_load_file( $rss_file );
$count=1;

foreach( $rss_feed->channel->item as $item  ) {
echo"<a title='$item->title' href='$item->link'> $item->title</a>";
$count++;
if($count >10)continue;
}
?>

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.