tags:

views:

69

answers:

1

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;
+2  A: 

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).

Felix Kling
+1 - I'm pretty sure that's what he wants to do too. The while loop appears to be infinite, as it simply checks the first record on the first go, and the last record every time after that.
zombat