using simplexml to parse a feed, but I want to grab the date of the oldest item in the feed. Does anyone know how to do it? Thanks
$rss = simplexml_load_file("http://search.twitter.com/search.atom?lang=en&q=foobar&rpp=100&page=1");
using simplexml to parse a feed, but I want to grab the date of the oldest item in the feed. Does anyone know how to do it? Thanks
$rss = simplexml_load_file("http://search.twitter.com/search.atom?lang=en&q=foobar&rpp=100&page=1");
If you simply want to get the last <entry>
element (in document-order) you can use SimpleXMLElement::xpath() and the last() function
http://www.w3.org/TR/xpath/ says:
child::para[position()=last()] selects the last para child of the context node
e.g.
$url = "http://search.twitter.com/search.atom?lang=en&q=foobar&rpp=100&page=1";
$feed = simplexml_load_file($url);
$feed->registerXPathNamespace('atom', 'http://www.w3.org/2005/Atom');
$entry = $feed->xpath('//atom:entry[position()=last()]');
if ( isset($entry[0]) ) {
$entry = $entry[0];
}
else {
die('not found');
}
var_dump($entry);
[position()=last()]
can be shortened to [last()]
If the oldest entry is not the last entry in document-order, you'll need something else.