PHP 调用webservice返回结果里带有头信息怎么获取里面的xml
下面是请求后返回的数据
如何获取其中的xml
HTTP/1.1 200 OK
Connection: close
Date: Fri, 27 May 2011 02:38:56 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Content-Length: 457
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><SubmitMmsResponse xmlns="http://MmsWebInterface.org/"><SubmitMmsResult><State>0</State><MsgID>110527103856160</MsgID><MsgState>审查</MsgState><Reserve>199702000</Reserve></SubmitMmsResult></SubmitMmsResponse></soap:Body></soap:Envelope>
如何获取其中的xml
HTTP/1.1 200 OK
Connection: close
Date: Fri, 27 May 2011 02:38:56 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Content-Length: 457
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><SubmitMmsResponse xmlns="http://MmsWebInterface.org/"><SubmitMmsResult><State>0</State><MsgID>110527103856160</MsgID><MsgState>审查</MsgState><Reserve>199702000</Reserve></SubmitMmsResult></SubmitMmsResponse></soap:Body></soap:Envelope>
作者: ck52110u 发布时间: 2011-05-27
假设返回数据的文件为:b.php ,在c.php中获取:
作者: jordan102 发布时间: 2011-05-27
LS可以清楚点吗 没太明白 为什么要去c里获取?
作者: ck52110u 发布时间: 2011-05-27
不好意思,点错了,接着上面:
PHP code
输出:
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><SubmitMmsResponse xmlns="http://MmsWebInterface.org/"><SubmitMmsResult><State& gt;0</State><MsgID>110527103856160< /MsgID><MsgState>审查< /MsgState><Reserve>199702000</Reserve></SubmitMmsResult></SubmitMmsResponse></soap:Body></soap:Envelope>
PHP code
$con=file_get_contents('b.php'); preg_match("/<\?xml[^>]+>(.*)<\/soap:Envelope>/is",$con,$arr); echo $arr[0];
输出:
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><SubmitMmsResponse xmlns="http://MmsWebInterface.org/"><SubmitMmsResult><State& gt;0</State><MsgID>110527103856160< /MsgID><MsgState>审查< /MsgState><Reserve>199702000</Reserve></SubmitMmsResult></SubmitMmsResponse></soap:Body></soap:Envelope>
作者: jordan102 发布时间: 2011-05-27
PHP code
$flg=0; $str_xml=""; while ($line = fgets($fp)) { if (ereg("^\<\?xml",$line)) { $flg=1; } if($flg){ $str_xml.=$line; } }
作者: yaoxin125 发布时间: 2011-05-27
也可以在写在一个文件里:
PHP code
PHP code
$str=<<<HTML HTTP/1.1 200 OK Connection: close Date: Fri, 27 May 2011 02:38:56 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 2.0.50727 Cache-Control: private, max-age=0 Content-Type: text/xml; charset=utf-8 Content-Length: 457 <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><SubmitMmsResponse xmlns="http://MmsWebInterface.org/"><SubmitMmsResult><State& gt;0</State><MsgID>110527103856160< /MsgID><MsgState>审查< /MsgState><Reserve>199702000</Reserve></SubmitMmsResult></SubmitMmsResponse></soap:Body></soap:Envelope> HTML; preg_match("/<\?xml[^>]+>(.*)<\/soap:Envelope>/is",$str,$arr); echo $arr[0];
作者: jordan102 发布时间: 2011-05-27
谢谢两位 明白了!!!
作者: ck52110u 发布时间: 2011-05-27
不懂路过帮顶
作者: XmlRequest 发布时间: 2011-05-27