把一根绳子剪成一根绳子
我如何只从这个响应中获取肥皂信封:
Content-Type: application/xop+xml; charset=UTF-8; type="application/soap+xml";
Content-Transfer-Encoding: binary
Content-ID: <[email protected]>
<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--
当我使用下面的代码时...
$sope_responce_with_garbage = stristr($response,'<soap:Envelope');
我也得到了字符串的其余部分:
<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--
但我只需要
之间的字符串> 和 。 我怎样才能得到这个结果?提前致谢。
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: <[email protected]>
<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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
strpos
查找任何字符串,并使用substr
:You can look-up any string with
strpos
and obtain a sub-string withsubstr
:您可以使用正则表达式 (regex)。
正则表达式用于搜索和修改字符串。
在您的情况下,您需要函数:
preg_match()
,它匹配模式并可选择将所有结果放入数组中。然后,您的结果将保存在变量
$matches[0]
中!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.Then, your result will be in the variable
$matches[0]
!