Parse only one item from RSS feed with PHP

irmaoryx

New Member
I'm trying to parse just one item form a rss feed. Basically, I'm trying to get the newest/last item from the rss feed and not parse the whole feed. Right now I have this code:\[code\]$x=$xmlDoc->getElementsByTagName('item');for ($i=0; $i<=2; $i++){$item_title=$x->item($i)->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue;$item_link=$x->item($i)->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue;$item_desc=$x->item($i)->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue;}\[/code\]However, this loops through all the items. I don't need all the elements/items. I just need the newest/last item on the feed. How can I achieve this? Would the following code work?\[code\]$x=$xmlDoc->getElementsByTagName('item');$item_title=$x->item->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue;$item_link=$x->item->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue;$item_desc=$x->item->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue;\[/code\]Thanks for the help!
 
Back
Top