Steven
Steven

Reputation: 1637

php count rss entries since a specific date/time

can anyone tell me why this code don't work:

$q = $_GET['q'];

// Load and parse the XML document

$rss =  simplexml_load_file("http://search.twitter.com/search.atom?lang=en&q=$q&rpp=100&page=1");

$Count1 = 0;

while(strtotime($rss->entry->published)>1270833600){

  foreach ($rss->entry as $item) {

    $Count1++;

  }

}

print "Total Record: ".$Count1;

Upvotes: 0

Views: 659

Answers (1)

Felix Kling
Felix Kling

Reputation: 816232

I think you want to do:

foreach($rss->entry as $item) {
   if(strtotime($item->published) > 1270833600) {
      $Count1++;
   }
}

Or assuming that the entries in the RSS feed are ordered properly:

$items = $rss->entry;
$item = current($items);
while(strtotime($item->published) > 1270833600){
    $Count1++;
    $item = next($items);
}

I don't know how SimpleXMLElement works internally so that is why I assign the array of elements to a new variable before (it might be that the internal array pointer gets reset otherwise).

Upvotes: 3

Related Questions