Hi, I am trying to check that if the response of the api contains something like PHP: <error> <message>No Videos found!</message> <code>####</code> </error> To do a show_error() in codeigniter. I've tried it with preg_match but no success for me. Any help would be greatly appreciated.
I have tried this but with no success PHP: if (preg_match('#<?xml version="1.0" standalone="yes"?>\s*<error>\s*<message>(.*)</message>\s*<code>(.*)</code>\s*</error>#i', $videosJson)); for this PHP: <?xml version="1.0" standalone="yes"?> <error> <message>No Videos found!</message> <code>2001</code> </error>
Ok I've managed to do it by doing this: PHP: if (strpos($videosJson, '<error>')) { preg_match('/<message>(.+?)<\/message>/', $videosJson, $match); show_error("<strong>$tag</strong>: $match[1]"); }
As the returned error is a XML document, you could have parsed it with simplexml like this to get a object of the error: $xml = simplexml_load_string($videosJson); print_r($xml);
Oh cool, thanks till. I've never worked with xml till now so I didn't even bother on searching some function like json_decode for xml but seem that it's the one you just said. But knowing that the solution I posted also works, I will keep that one for now. Thanks again, Alex