Web Analytics Made Easy -
StatCounter RSS FEED (php) - CodingForum

Announcement

Collapse
No announcement yet.

RSS FEED (php)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • RSS FEED (php)

    Code:
    <?php
    
     $xml=("http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml");
    
    
    $xmlDoc = new DOMDocument();
    $xmlDoc->load($xml);
    
    //get elements from "<channel>"
    $channel=$xmlDoc->getElementsByTagName('channel')->item(0);
    $channel_title = $channel->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue;
    $channel_link = $channel->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue;
    $channel_desc = $channel->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue;
    
    //output elements from "<channel>"
    echo("<p><a href='" . $channel_link. "'>" . $channel_title . "</a>");
    echo("<br />");
    echo($channel_desc . "</p>");
    
    //get and output "<item>" elements
    $x=$xmlDoc->getElementsByTagName('item');
    for ($i=0; $i<[B]4[/B]; $i++)
     {
     $item_title=$x->item($i)->getElementsByTagName('title') ->item(0)->childNodes->item(0)->nodeValue;
     $item_link=$x->item($i)->getElementsByTagName('link') ->item(0)->childNodes->item(0)->nodeValue;
     $item_desc=$x->item($i)->getElementsByTagName('description') ->item(0)->childNodes->item(0)->nodeValue;
    
     echo ("<p><a href='" . $item_link . "'>" . $item_title . "</a>");
     echo ("<br />");
     echo ($item_desc . "</p>");
     }
    ?>
    in the second loop i used 4(bold) so i got only 4 feeds but i want all feeds but i am not understanding what conditions i would use
    http://www.atneshop.com/
    http://channelishop.com/

  • #2
    1. please post your code in PHP tags not CODE tags...
    2. Do a count on $xmlDoc->getElementsByTagName('item') and see what happens.....

    Comment

    Working...
    X