tags:

views:

89

answers:

1

For example, if there is an RSS feed and for some reason it is down or cannot be grabbed I want to display a simple message saying "feed cannot be grabbed".

Right now PHP spits out a really ugly warning message.

note:I do not need to know whether it is valid. I just need to know if the feed actually works. I do not want to turn off warnings. I want to spit out a simple echo if the feed is not working. I am using PHP no libraries.

Any thanks would be awesome!

Rick

A: 

You can manually handle any XML parsing errors by using the libxml_use_internal_errors function.

An example can be found here

Inspire
That was helpful, but I am still getting this error. (The url is an incorrect one, so I could test)Warning: DOMDocument::load(http://rss.cnn.com/rss) [domdocument.load]: failed to open stream: HTTP request failed! HTTP/1.0 404 Feed not found error: FeedBurner cannot locate this feed URI. in /home/content/r/i/c/rickchendesign/html/twg/rssLib.php on line 17
Rick Chen
Indeed it seems that there is no way to suppress the error when using DOMDocument (I thought you were using SimpleXML) "cleanly". You could create a custom PHP error handler for it. Though admittedly that seem rather ugly and I feel PHP really should have made it easier to handle warnings in this case.
Inspire
I should have used Simple XML. I started this project as a learn PHP project. At least I learned. Thanks for your help Inspire.Rick
Rick Chen