Archive for May, 2009

Parsing XML and RSS Feeds with PHP

Saturday, May 2nd, 2009

<?php

$doc = new DOMDocument();
$doc->load(’http://feeds.latimes.com/latimes/features/health?format=xml’);
$arrFeeds = array();
foreach ($doc->getElementsByTagName(’item’) as $node)
{
$title = $node->getElementsByTagName(’title’)->item(0)->nodeValue;
$description = $node->getElementsByTagName(’description’)->item(0)->nodeValue;
$link = $node->getElementsByTagName(’link’)->item(0)->nodeValue;
$pubDate = $node->getElementsByTagName(’pubDate’)->item(0)->nodeValue;

echo “<b><a href=” . $link . ” target=_blank>” . $title . “</a></b><br /> “;
echo $description . “<br />”;
echo $pubDate . “<br />”;
}
?>
See example.