Sup peeps. I got an issue here. I receive this data and just want to strip the <SOAP-ENV
elements with their respective closing elements.
This is the header and body start part.
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<SOAP-ENV:Header></SOAP-ENV:Header>
<SOAP-ENV:Body>
<VisionDataExchange>
Now I run my regular expession on $xml
the variable containing the entire xml data:
$xml = preg_replace("/<\\/?SOAP(.|\\s)*?>/",'',$xml);
Now my result is this. It actually stripped the openening tags but none of the closing tags? What am I missing here?
<?xml version="1.0" encoding="UTF-8"?>
</SOAP-ENV:Header>
<VisionDataExchange>
I suggest just matching everything inside a tag, not any character or whitespace
. Have a look at this regex:
$re = "/<\\/?SOAP[^<>]+?>/";
$str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">
<SOAP-ENV:Header></SOAP-ENV:Header>
<SOAP-ENV:Body>
<VisionDataExchange>";
$subst = "";
$result = preg_replace($re, $subst, $str);
Ok, so after nearly breaking my skull on my desk, i found what the issue was. The regex is indeed working perfectly!there was a hidden \
in the string that caused the regex to fail.