我正在使用SimplePie来显示来自多个来源的RSS结果,但是我发现有几个我不需要看到。我如何仅显示5天或更小的结果?
这是我当前的PHP代码:
foreach ($feed->get_items(0) as $item):
$url = $item->get_permalink();
$title = $item->get_title();
$date = $item->get_date('F j, Y - g:i a');
$description = $item->get_description();
if (strpos($url,'craigslist') !== false) {
echo ' <div id="linkCell" style="width: 100%;">';
echo ' <div id="vAlign">';
echo ' <p class="linkTitle">';
echo ' <a href="'.$url.'" title="'.$title.'">'.$title.'</a>';
echo ' </p><br />';
echo ' <span class="date">'.$date.'</span><br>';
echo ' <p class="description">'.$description.'</p>';
echo ' </div>';
echo ' </div>';
}
endforeach;
提前致谢!
答案 0 :(得分:0)
这样的事情应该有效。需要将日期转换为unix时间戳,找到差异,然后将其转换为天数。
foreach ($feed->get_items(0) as $item):
$url = $item->get_permalink();
$title = $item->get_title();
$date = $item->get_date('F j, Y - g:i a');
$datestrtotime = strtotime($date);
$now = time();
$datediff = $now - datestrtotime;
$daysdifference = floor($datediff/(60*60*24));
$description = $item->get_description();
if($daysdifference>5)
{
if (strpos($url,'craigslist') !== false) {
echo ' <div id="linkCell" style="width: 100%;">';
echo ' <div id="vAlign">';
echo ' <p class="linkTitle">';
echo ' <a href="'.$url.'" title="'.$title.'">'.$title.'</a>';
echo ' </p><br />';
echo ' <span class="date">'.$date.'</span><br>';
echo ' <p class="description">'.$description.'</p>';
echo ' </div>';
echo ' </div>';
}
}
endforeach;