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
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++;
}
}
?>

Link to comment
Share on other sites

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;
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.