Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9027805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:50:04+00:00 2026-06-16T06:50:04+00:00

I’m attempting to pull in an RSS feed, but I only want to show

  • 0

I’m attempting to pull in an RSS feed, but I only want to show one of the items – a random number – not all of them. I’ve set up a test using a for loop, but can’t seem to get it to work. I come from a JS background. Any help or hints would be much appreciated!

<?php

$url = "http://abc.net.au/bestof/bestofabc.xml";

$rss = simplexml_load_file($url);

if ($rss) {

    $items = $rss->channel->item;

    for ($i = 0; $i < count($items); $i++){

        if ($i == 2) {

            echo($items[$i]); // doesn't show anything
        }
    }
}

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T06:50:05+00:00Added an answer on June 16, 2026 at 6:50 am

    You have got basically two options here, for easy of use I assign the item to a variable of its own first:

    $item = $items[$i];
    

    And then the two options for debugging:

    var_dump($item);
    echo $item->asXML();
    

    The first line will create a var_dump, which is PHP and in this case even SimpleXML specific:

    class SimpleXMLElement#193 (5) {
      public $title =>
      string(29) "Asylum seeker system overload"
      public $link =>
      string(29) "http://www.abc.net.au/bestof/"
      public $description =>
      class SimpleXMLElement#287 (0) {
      }
      public $pubDate =>
      string(31) "Thu, 22 Nov 2012 00:00:00 +1100"
      public $guid =>
      string(8) "s3638457"
    }
    

    The second line will create something I bet is common to you, the XML itself:

    <item>
                <title>Asylum seeker system overload</title>
                <link>http://www.abc.net.au/bestof/</link>
                <description><![CDATA[
                <img style="float:right;" src="http://www.abc.net.au/common/images/news_asylum125.jpg" alt="Asylum seeker detainees (ABC News)">
                <p>The Australian government is preparing to allow thousands of asylum seekers to love in the community.</p>
                <ul>
    
                    <li><a href="http://mpegmedia.abc.net.au/news/lateline/video/201211/LATc_FedNauru_2111_512k.mp4">Watch (4:23)</a></li><li><a href="http://www.abc.net.au/lateline/content/2012/s3638174.htm">More - Lateline</a></li>
                </ul>
                ]]></description>
    
                <pubDate>Thu, 22 Nov 2012 00:00:00 +1100</pubDate>
                <guid isPermaLink="false">s3638457</guid>
            </item>
    

    You did not see any output with:

    echo $items[$i];
    

    because that <item> element does not have a value, but just subelements. For example

    echo $items[$i]->title;
    

    Will output the string:

    Asylum seeker system overload
    

    I hope this is helpful and sheds some light. You find the demo here, it also shows that you can make use of foreach:

    $i = 0;
    foreach ($rss->channel->item as $item)
    {
        if ($i++ == 2) {
            var_dump($item);
            echo $item->asXML(), "\n", $item->title;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I want to show the soap response to UIWebview.. my soap response is, <p><img
I want to construct a data frame in an Rcpp function, but when I
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.