**I have a string**

$string ="   HTTP/1.1 200 OK
    Connection: close
    Date: Tue, 25 Sep 2011 14:09:35 GMT
    Accept: text/xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
    Server: Apache-Coyote/1.1
    Content-Length: 12881
    Content-Type: text/xml;charset=utf-8
    Client-Date: Tue, 25 Sep 2012 14:09:35 GMT
    Client-Peer: 123.46.53.940:8080
    Client-Response-Num: 1



<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
    <soap-env:Header/>
    <soap-env:Body>
        <PlexViewResponse Command="rtrv-ngfs-subscriber-v2" CongestionIndicator="false" Fsdb="fsdb0" RequestId="" SessionId="Imsptools01:7524768" Status="SUCCESS" SwitchName="ps3il001fsk2">
            <AlternateOtasRealm>stas-stdn.fsimsgroup0-000.ps1tx001fsk2.cvoip.ims.sbc.com</AlternateOtasRealm>
            <SubParty>
                <DisplayName>SDP-Lite</DisplayName>
                <Category>RESIDENTIALSUBSCRIBER_R2</Category>

                ";

`How do I remove this part of the string

HTTP/1.1 200 OK
    Connection: close
    Date: Tue, 25 Sep 2011 14:09:35 GMT
    Accept: text/xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
    Server: Apache-Coyote/1.1
    Content-Length: 12881
    Content-Type: text/xml;charset=utf-8
    Client-Date: Tue, 25 Sep 2012 14:09:35 GMT
    Client-Peer: 123.46.53.940:8080
    Client-Response-Num: 1



and get the remaining part.

that is string starting from 

<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Header/>
<soap-env:Body>
    <PlexViewResponse Command="rtrv-ngfs-subscriber-v2" CongestionIndicator="false" Fsdb="fsdb0" RequestId="" SessionId="Imsptools01:7524768" Status="SUCCESS" SwitchName="ps3il001fsk2">
        <AlternateOtasRealm>stas-stdn.fsimsgroup0-000.ps1tx001fsk2.cvoip.ims.sbc.com</AlternateOtasRealm>
        <SubParty>



        Thanks.`

How do you retrieve data?

?????

How to extract substring.

Member Avatar

diafol

For this you could use regex or simpleXML or DOMdocument or another parsing class.

But if you just need to cut off the header:

$string ='HTTP/1.1 200 OK
    Connection: close
    Date: Tue, 25 Sep 2011 14:09:35 GMT
    Accept: text/xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
    Server: Apache-Coyote/1.1
    Content-Length: 12881
    Content-Type: text/xml;charset=utf-8
    Client-Date: Tue, 25 Sep 2012 14:09:35 GMT
    Client-Peer: 123.46.53.940:8080
    Client-Response-Num: 1
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
    <soap-env:Header></soap>
    <soap-env:Body>
        <PlexViewResponse Command="rtrv-ngfs-subscriber-v2" CongestionIndicator="false" Fsdb="fsdb0" RequestId="" SessionId="Imsptools01:7524768" Status="SUCCESS" SwitchName="ps3il001fsk2">
            <AlternateOtasRealm>stas-stdn.fsimsgroup0-000.ps1tx001fsk2.cvoip.ims.sbc.com</AlternateOtasRealm>
            <SubParty>
                <DisplayName>SDP-Lite</DisplayName>
                <Category>RESIDENTIALSUBSCRIBER_R2</Category>';


preg_match("/(<soap-env:Envelope.*)/s",$string,$matches);
echo '<pre>' . htmlentities($matches[0]) . '</pre>';

The data you need will be in $matches[0] variable.

In addition, I asked that question because if you are using curl, just change the settings, like:

curl_setopt($ch, CURLOPT_HEADER, 0);

and you will get just the XML part. Bye!