Array
(
[description] => HTTP/1.1 200 OK
Set-Cookie: JSESSIONID=40EA513DEFAE87D378EACB79C4E8A1B5; Path=/ipcam
Content-Type: text/xml;charset=UTF-8
Transfer-Encoding: chunked
Date: Thu, 27 Jun 2013 01:08:23 GMT
Server: Apache-Coyote/1.1c1b
<?xml version="1.0" encoding="UTF-8" ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://www.liveipc.com/UserService/">
<SOAP-ENV:Body>
<ns1:UserOperationResponse>
<WSResponse>
<Version>1.0</Version>
<CharSet>GBK</CharSet>
<TransactionName>UserLogin</TransactionName>
<Random>244ab25cf7f0258401c2ae0b038ead0a</Random>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
0
}这是原字符串,我想取出其中的xml那段字符串,要肿么来写那个正则,自己写的总是为空,整不出来。结果应该为:
<?xml version="1.0" encoding="UTF-8" ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://www.liveipc.com/UserService/">
<SOAP-ENV:Body>
<ns1:UserOperationResponse>
<WSResponse>
<Version>1.0</Version>
<CharSet>GBK</CharSet>
<TransactionName>UserLogin</TransactionName>
<Random>244ab25cf7f0258401c2ae0b038ead0a</Random>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

解决方案 »

  1.   


    我写的正则都只能取一行的数据,比如取xml第一行的数据:
    '/\<\?.*\?\>/'可我如果取多行xml数据时就取不到,比如:
    '/\<\?xml.*Envelope\>/'
      

  2.   

    $preg='/<\?xml version\="1\.0" encoding\="UTF\-8" \?>(.*?)\}/ius';
    preg_match_all($preg, $str, $lined);
    print_r($lined);自己看,剩下的自己处理,记得后面不要漏了ius,否则就为空了,后面的是不区分大小写以及多行模式匹配的
      

  3.   


    我写的正则都只能取一行的数据,比如取xml第一行的数据:
    '/\<\?.*\?\>/'可我如果取多行xml数据时就取不到,比如:
    '/\<\?xml.*Envelope\>/'你这个也可以
    $preg='/\<\?xml.*Envelope\>/ius';
    preg_match_all($preg, $str, $lined);
    print_r($lined);
    结果自己看
      

  4.   

    关键是后面的ius不区分大小写多行匹配模式