简体   繁体   English

自特定日期/时间以来,PHP计数rss条目

[英]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;

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: 或假设RSS feed中的条目已正确排序:

$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). 我不知道SimpleXMLElement在内部如何工作,所以这就是为什么我之前将元素数组分配给新变量(否则可能是内部数组指针被重置了)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM