2015-06-27 38 views
1

我有一個php文件,它從其他頁面獲取rss提要並在我自己的頁面上實現它們...問題是如何過濾出幾小時的RSS提要?在rss feed中解析php過濾小時php

<?php 
    $html = ""; 
    $url = "http:www.yoursite.com/rss"; 
    $xml = simplexml_load_file($url); 
    for($i = 0; $i < 1; $i++){ 
     $title = $xml->channel->item[$i]->title; 
     $link = $xml->channel->item[$i]->link; 
     $description = $xml->channel->item[$i]->description; 
     $pubDate = $xml->channel->item[$i]->pubDate; 
     $pubDate = strftime("%Y-%m-%d" "%H:%M:%S", strtotime($pubDate)); 
     //%H shows the pubDate Hour 

     $html .= "<h3>$title</h3>"; 
     $html .= "$description"; 
     $html .= "<br /><a href='$link'>Weiterlesen</a>"; 
     $html .= "<br /><br />$pubDate"; 
    } 
    echo $html; 
?> 

目標就像擁有所有在10pm發佈的feed!

回答

0

您可以將xml對象放入數組中,並查看該值是否存在。

$var = array ('1pm','2pm','10pm') 

if (in_array('10pm', $var, true)) { 

echo 'this is 10pm'; 

} 
+0

我不使用XML文件或將其保存在數據庫......我的PHP代碼裏面的html ...所以它只是告訴我的通訊 – Bob

+0

右邊的最後一個職位,但是當你複製和粘貼http:www.yoursite.com/rss到瀏覽器窗口返回什麼? 在你的情況下,你從這些變量拉動rss feed url(這是xml或json)的所有信息: $ title = $ xml-> channel-> item [$ i] - > title; $ link = $ xml-> channel-> item [$ i] - > link; etc ... 你想要做的就是把這些變量放入一個數組中,然後看看該數組中是否存在一個特定的值。 – Society43

+0

這裏的帖子可能會幫助你 http://stackoverflow.com/questions/12934373/php-scripts-gets-a-node-value-if-it-equals-specified-value-changes-a-node- va – Society43