Quantcast
Channel: Parse only one item from RSS feed with PHP - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Parse only one item from RSS feed with PHP

$
0
0

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:

$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;}

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?

$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;

Thanks for the help!


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>