I load a bunch of rss feeds using the DOM, and sometimes one of them will be 404 instead of creating a file. The problem is that the web server sends an html 404 page instead of the expected xml file using this code:
$rssDom = new DOMDocument();
$rssDom->load($url);
$channel = $rssDom->getElementsByTagName('channel');
$channel = $channel->item(0);
$items = $channel->getElementsByTagName('item');
I get this warning:
Warning: DOMDocument::load() [domdocument.load]: Entity 'nbsp' not defined
Following this error:
Fatal error: Call to a member function getElementsByTagName() on a non-object
Usually this code works fine, but on the occasion when I get 404, it does nothing. I tried the standard try-catch around the load statement, but it didn't seem to catch it.
source
share