You'll find it a lot easier if you also process the outer SOAP document with SimpleXML, rather than trying to force it into a regex. It might look a bit complicated because of the namespaces, but it's quite straightforward using the SimpleXML::children()
method:
$soap = simplexml_load_string($output);$response = $soap ->children('http://schemas.xmlsoap.org/soap/envelope/') ->Body ->children('http://api-v1.gen.mm.vodafone.com/mminterface/request') ->ResponseMsg;$xml = simplexml_load_string(trim($response));// ...
See https://3v4l.org/iQIAT for a full demo
(As an aside, using json_encode
directly with a SimpleXML object can have a couple of strange side-effects, but should work ok with this document. You might find it more reliable to just extract the values you want using SimpleXML's own API, e.g. $xml->ResponseCode
)