Image Caption

Monday, March 18, 2013

Soap response to php array


//Php Explode is best way to convert the soap response to PHP array

function soaptoarray($response)
{

$search  = array('<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"','<soapenv:Header/','<soapenv:Body','</', '<');
$replace = array(' ',' ',' ','@end@', '*start*');
$customer=str_replace($search, $replace, $response);
$soapres =explode('*start*',$customer);

foreach($soapres as $key=>$value)
{
$res[$key]=$value;
$temp=explode('@end@',$value);
$tempval=explode('>',$temp[0]);
$tmp=explode("State",$tempval[0]);
}

$resp{$tempval[0]}=$tempval[1];

}

return $resp;
}


//Output php array similar to:


Array
(
    [ ] =>  
    [p711:getDeviceResponse xmlns:p711="http://provision.xbridge.com"] => 
    [getDeviceResult] => 
    [Status Code="0" Message="Done"/] => 
    [Device Id="B0112121" Phone="12312312331" Serial="8901410423121235279"] => 
    [DeviceStatus] => Deactivated
    [State Code="0" Name="Deactivated"/] => 
    [Network Id="1" Name="AT&T" Type="Gold"/] => 
    [Customer] => 00001238
    [Contract Description="FRED SEIFU" Id="43124" Name="FREDS121"/] => 
    [LLI] => B011218
    [APN] => gp102.mo122.net
    [ICCID] => 89022103423295536629
    [MSISDN] => 512233212
    [IMSI] => 310423343553527
    [PIN1] => 1111
    [PUK1] => 412129385
    [PIN2] => 2222
    [PUK2] => 2222
)