Thursday, 15 January 2015

php - Only display elements 5 days old or younger? -



php - Only display elements 5 days old or younger? -

i using simplepie display rss results multiple sources, i'm finding there's several don't need see. how show results 5 days old or younger?

here's current php code:

foreach ($feed->get_items(0) $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;

thanks in advance!

something should work. need convert date unix timestamps, find difference, , convert days.

foreach ($feed->get_items(0) $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;

php rss simplepie

No comments:

Post a Comment