The following code takes a news feed and prints out the titles in a list.
Code: Select all
$dom = new domdocument;
$url = 'http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/uk/rss.xml';
$dom->loadHTMLFile($url);
echo '<h1>BBC UK News Headlines</h1>';
echo '<ul>';
$items = $dom->getElementsByTagName("item");
foreach($items as $item) {
$titles = $item->getElementsByTagName('title');
foreach($titles as $title)
{
$titleText = $title->firstChild->data;
}
$links = $item->getElementsByTagName('link');
foreach($links as $link)
{
$linkLoc = $link->firstChild->data;
echo $linkLoc;
}
echo '<li><a href="' . $linkLoc . '">'.$titleText.'</a></li>';
}
echo '</ul><br/><br/>';So it investigate further I used the following command near the top of my code:
Code: Select all
echo $dom->saveHtml();Why is this? Is it something really simple that I am missing? I have tried this on 3 news feeds now yahoo, google and the BBC.
Any help will be greatly appreciated. Thanks in advance