开发者

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&开发者_Go百科amp;q=$q&rpp=100&page=1");

$Count1 = 0;

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

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

    $Count1++;

  }

}

print "Total Record: ".$Count1;


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜