Questions:
1. I've been looking around on the internet as much as I can, and it seems like maybe I need to validate the xml first. Is this correct?
2. Or, is there a way to rewrite the code so it allows more flexibility for less than perfect xml?
3. Or, if there were a way to say don't display the errors if there are issues, that would work as well.
I'm sure there won't be errors often as the news sources are the NY Times, CNN Money, and other big name news companies, but it'd be nice to not have to worry about it. I'm fairly new to php, but I'm willing to learn. If you know of a good function for this purpose, I'd appreciate the help. Here's the code I'm using:
In the first part, I'm loading the xml file from the first source, and putting the items into arrays:
Code: Select all
$doc1 = new DOMDocument();
$doc1->load('http://www.nytimes.com/services/xml/rss/nyt/Business.xml');
$arrFeeds1 = array();
foreach ($doc1->getElementsByTagName('item') as $node1) {
$itemRSS1 = array (
'title' => $node1->getElementsByTagName('title')->item(0)->nodeValue,
'link' => $node1->getElementsByTagName('link')->item(0)->nodeValue,
);
array_push($arrFeeds1, $itemRSS1);
}
Code: Select all
$ny = str_replace("&","&","<li><a href=\"".$arrFeeds1[0]['link']."\" class=\"feed\">".$arrFeeds1[0]['title']."</a><span class=\"source\"> - NY Times</span></li>\n");
Code: Select all
echo "<ul>\n";
echo $ny;
echo "</ul>\n";
Rob