PHP RSS Parsing Tutorial

I made a tutorial a while back which parsed RSS feeds however it was really simple, in fact too simple…So here is a completely new script which parses the feeds in a completely different way.
So heres a walk-through of the script…
Firstly we need to represent the feed as an xml document. Using DOMDocument…
More information here
$xmldoc = new DOMDocument();
Now we need to load the RSS Feed.
$xmldoc->load('RSS Feed Address');
Now the feed is loaded we need to make sure that each item in the feed is loaded individually.
foreach ($xmldoc->getElementsByTagName('item') as $feeditem) {
Now we need to show the feed. This will also show it as a link which the previous script didn’t do.
echo "getElementsByTagName('link')->item(0)->nodeValue . "\">
“;
echo $feeditem->getElementsByTagName(’title’)->item(0)->nodeValue
. “\n”;
}
That snippet of code looks complicated however if you break it down its very simple. It’s just a hyperlink in HTML with PHP in the middle.
Demo - Using The Flick Zone Feed
Heres a full Source code for you copy and pasters out there….
PHP Code:
<?php
load('RSS Feed Address');
foreach ($xmldoc->getElementsByTagName('item') as $feeditem) {
echo "getElementsByTagName('link')->item(0)->nodeValue . "">";
echo $feeditem->getElementsByTagName('title')->item(0)->nodeValue . "\n";
}
?>
See You !