I am using SimpleXML to load a response from an API call. However, if the server returns an error, it only returns a single XML tag with the error message:
<err>ERROR MESSAGE HERE</err>
I’m currently using this code to parse the API response:
$parsedresponse = simplexml_load_string($response);
The $parsedresponse variable contains only the error message. However, I need a way to check if the <err> tag is present so I know if there was an error. I can’t seem to figure out how to do this…
Thank you!
If
errtag is the root tag use the following condition to trace the error.If its the first child use