想要使用PHP过滤datepicker的XML / RSS

时间:2016-06-12 07:18:04

标签: php rss

<?php
//get the q parameter from URL
$q=$_GET["q"];

//find out which feed was selected
if($q=="GEO") {
  $xml=("http://feeds.feedburner.com/GeoBulletins");
} elseif($q=="National") {
  $xml=("http://feeds.feedburner.com/geo/GiKR");
}
elseif($q=="World") {
  $xml=("http://feeds.feedburner.com/geo/wUIl");
}
elseif($q=="Sports") {
  $xml=("http://feeds.feedburner.com/GeoSport-GeoTvNetwork");
}
elseif($q=="CNN") {
  $xml=("http://rss.cnn.com/rss/edition.rss");
}
elseif($q=="World") {
  $xml=("http://rss.cnn.com/rss/edition_world.rss");
}
elseif($q=="Technology") {
  $xml=("http://rss.cnn.com/rss/edition_technology.rss");
}
elseif($q=="Sports") {
  $xml=("http://rss.cnn.com/rss/edition_sport.rss");
}

//$xmlDoc = new DOMDocument();
//$xmlDoc->load($xml);

$rss = new DOMDocument();
  $rss->load($xml);
  $feed = array();
  foreach ($rss->getElementsByTagName('item') as $node) {
    $item = array ( 
      'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
      'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
      'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
      'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
      );
    array_push($feed, $item);
  }

  $limit = 10;
  for($x=0;$x<$limit;$x++) 
  {
    if ( date('l', strtotime($feed[$x]['date']) ) == 'Saturday' ||'Sunday')
    {
      $title = str_replace(' & ', ' &amp; ', $feed[$x]['title']);
      $link = $feed[$x]['link'];
      $description = $feed[$x]['desc'];
      $date = date('l F d, Y', strtotime($feed[$x]['date']));
      echo '<p><strong><a href="'.$link.'" title="'.$title.'">'.$title.'</a></strong><br />';
      echo '<small><em>Posted on '.$date.'</em></small></p>';
      echo '<p>'.$description.'</p>';
    }
  }
  //date('l F d, Y', strtotime($feed[$x]['date']) ) == 'Wednesday June 08, 2016'
//get elements from "<channel>"
?>

在Feed中,我尝试仅显示使用PHP在我网站上的日期选择器中选择的确切日期上的帖子。这是我的代码......我该如何修改?

我试过了 date('l F d, Y', strtotime($feed[$x]['date']) ) == 'Wednesday June 08, 2016'显示确切的日期帖子但不起作用

0 个答案:

没有答案