Search code examples
rsscountfeed

Rss feeds: get certain amount of tweets


Is it possible to give a parameter when getting the RSS feeds to determine how many feeds it should get?

I don't want to load all the RSS feeds, but only the first 20. Is this possible?

Thanks!


Solution

  • You can set the limit. By executing a Loop in limit. So it will parse the xml and your program will read items in loop. Once the loop crossed the limit. Just break the loop.

    $i=0;
    while ($reader->read()) {
    
    if($i>=10)
           break;
    else{
    switch ($reader->nodeType) {
    
    case (XMLREADER::ELEMENT):
    
    if ($reader->localName == "item") {
    
    $node = $reader->expand();
    
    $dom = new DomDocument();
    
    $n = $dom->importNode($node,true);
    
    $dom->appendChild($n);                           
    
    $sxe = simplexml_import_dom($n);
    
    $url = (String)$sxe->url;
    $title=(String)$sxe->title;
    }
    
    }
    }
    

    In the above code $i is the limiter. Where we can limit number feed to display in the page.