Q:

Cut a string up to a string

How do I only get the soap envelope from this response:
Content-Type: application/xop+xml; charset=UTF-8; type="application/soap+xml";
Content-Transfer-Encoding: binary
Content-ID: <root.message@cxf.apache.org>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body><MResponse xmlns="http://xxx.gateway.abc.abcd.com"><return><transaction_id>123456</transaction_id><error_code>109</error_code><error_desc>Service is inactive (suspended/terminated)</error_desc><error_list>na</error_list><success_list></success_list></return></MResponse></soap:Body></soap:Envelope>
------=_Part_0_9361192.1321179416623--

When I use the code below...
$sope_responce_with_garbage = stristr($response,'<soap:Envelope');

I get the rest of the string as well:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body><MResponse xmlns="http://xxx.gateway.abc.abcd.com"><return><transaction_id>123456</transaction_id><error_code>109</error_code><error_desc>Service is inactive (suspended/terminated)</error_desc><error_list>na</error_list><success_list></success_list></return></MResponse></soap:Body></soap:Envelope>
    ------=_Part_0_9361192.1321179416623--

But I only need the string between <soap:Envelope> and </soap:Envelope>.
How can I get that result? Thanks in advance.

A:

You can use regular expressions (regex).
Regex are used to search and modify strings.
In your case you'd need the function: preg_match() which matches a pattern and optionally puts all results in an array.
$pattern = '/<soap:Envelope.*?>(.*)<\/soap:Envelope>/i'; // searches for your pattern
preg_match($pattern, $response, $matches);

Then, your result will be in the variable $matches[0]!

