-1

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.

Tim S.
  • 13,597
  • 7
  • 46
  • 72
riad
  • 7,144
  • 22
  • 59
  • 70
  • possible duplicate of [How do I read SOAP reply Envelope by PHP](http://stackoverflow.com/questions/8111079/how-do-i-read-soap-reply-envelope-by-php) – hakre Nov 14 '11 at 12:22
  • Next to DOMDocument see as well PHP's string functions: http://php.net/strings – hakre Nov 14 '11 at 12:23
  • that was read the sope reply.Now i can read the reply.But in this question i need to cut the string between the mentioned tag.thx. – riad Nov 14 '11 at 12:23
  • How are you getting the response? – Eric Nov 14 '11 at 12:24
  • please keep in mind that it's SOAP not SOPE. Next to that, it looks like you have some HTTP response. What specific input data is that? Looks like multipart data. Can you be more specific? (and please correct the typos). – hakre Nov 14 '11 at 12:26
  • sorry.that was about my previous question.it's nothing related with this question.anyway getting response:$response=$client->response; – riad Nov 14 '11 at 12:26
  • @hakre: it's a soap response. basically $response=$client->response; used to receive the response. – riad Nov 14 '11 at 12:30

2 Answers2

1

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]!

Tim S.
  • 13,597
  • 7
  • 46
  • 72
0

You can look-up any string with strpos and obtain a sub-string with substr:

$upto = '';
$end = '</soap:Envelope>';
$r = strpos($subject, $end);
if ($r !== FALSE)
{
   $upto = substr($subject, 0, $r + strlen($end));
}
hakre
  • 193,403
  • 52
  • 435
  • 836