根据RSS Feed的发布日期提取项目

时间:2013-04-17 16:12:05

标签: php rss

我正在从BBC体育网站上提取RSS Feed,显示如下项目:

<item> 
  <title>VIDEO: Warnock on why he left Leeds</title>  
  <description>Dan Walker is joined for this week's Focus Forum by Neil Warnock, who discusses his departure from Leeds United earlier this month.</description>  
  <link>http://www.bbc.co.uk/sport/0/football/22136090</link>  
  <guid isPermaLink="false">http://www.bbc.co.uk/sport/0/football/22136090</guid>  
  <pubDate>Tue, 16 Apr 2013 08:27:55 GMT</pubDate>  
  <media:thumbnail width="66" height="49" url="http://news.bbcimg.co.uk/media/images/66985000/png/_66985898_warnock.png"/>  
  <media:thumbnail width="144" height="81" url="http://news.bbcimg.co.uk/media/images/66985000/png/_66985900_warnock.png"/> 
</item>  

我只想拉7天前发布的项目。到目前为止,我有:

<?php
  $cnt=0;
foreach($rss->channel->item as $item){
    if ($cnt==100) {
      break;
    }
foreach($rss->entry as $item) {
   if ($item->published) > "") {
  print_r($item);
   }
?>

非常不确定第二个foreach,搜索此网站页面寻找答案但没有运气!

提前致谢!

1 个答案:

答案 0 :(得分:0)

您应该将RSS提要中的值转换为DateTime对象,然后使用比较器

在这里查看示例#2: http://php.net/manual/en/datetime.diff.php