Reputation: 1449
I want to be able to detect error with SimpleXMLElement, the errors being:
failed to open HTTP stream
failed to load external entity
Uncaught exception 'Exception' with message 'String could not be parsed as XML'
I have the following code to attempt to detect error.
$xml = new SimpleXMLElement("https://mail.google.com/mail/feed/atom",null,true);
if ($xml === FALSE) {
echo "Wrong username/password combination.";
}
This doesn't work.... how do I make error detection work?
Upvotes: 0
Views: 608
Reputation: 14941
Exceptions can be caught using a try catch construction:
try {
$oXml
}
catch(Excepton $oException) {
// Something went wrong!
}
For the HTTP / Load problems I suggest you use a combination of:
Upvotes: 1