Hi there,
I'm using this piece of code to embed news to a site via RSS.
// Accepts an RSS feed URL and outputs a list of links from it
function RestfulLinks($limit) {
$delicious = new RestfulService('http://www.cnbc.com/id/19811193/device/rss/rss.xml');
$conn = $delicious->connect();
$result = $delicious->getValues($conn, "channel", "item")->getRange(0,$limit);
$output = '';
foreach ($result as $key => $value) {
$output = '<b>' . $value->pubDate . '</b>' . ' – ' . $description . ' <a class="thickbox" href="'.$value->link.'?KeepThis=true&TB_iframe=true&height=600&width=960">More...</a>';
}
return $output;
}
This works perfectly, but sometimes I get the following error (and website is unavailable!):
Error: Uncaught Exception: String could not be parsed as XML
At line 217 in ......./public_html/sapphire/api/RestfulService.php
It looks like temporarily there is something strange going on in the feed (in this case wrong formatted or unavailable RSS feed?). Is there a way to make sure that this error doesn't affect my complete site. Something like: if feed cannot be parsed: do nothing.
Help is more than welcome, thanks in advance!