- var_dump: documentation ( source)
- json_decode: documentation ( source)
- str_replace: documentation ( source)
- preg_replace: documentation ( source)
- json_encode: documentation ( source)
<?php
$xml = '
<?xml version="1.0" encoding="UTF-8" ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<OTA_HotelResNotifRS xmlns="http://www.opentravel.org/OTA/2003/05" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.opentravel.org/OTA/2003/05 OTA_HotelResNotifRQ.xsd" TimeStamp="2017-04-25T13:54:59+02:00" Version="1.003" EchoToken="58ff3910062c0">
<Success />
<HotelReservations>
<HotelReservation>
<UniqueID Type="14" ID="24671-CH108B541" />
<ResGlobalInfo>
<HotelReservationIDs>
<HotelReservationID ResID_Type="14" ResID_Value="24671-CH108B541" />
</HotelReservationIDs>
</ResGlobalInfo>
</HotelReservation>
</HotelReservations>
</OTA_HotelResNotifRS>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
';
function parseReservationResponseXML($content)
{
$content = str_replace('<?xml version="1.0" encoding="UTF-8"?>', '', $content);
/*
* RateTiger response da xsi eklenince hata aldigimizdan dolayi bu bolum siliniyor.
*/
$content = str_replace("xsi:schemaLocation='http://www.opentravel.org/OTA/2003/05 OTA_HotelResNotifRQ.xsd'", '', $content);
$requestParams = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $content);
try {
$xml = new \SimpleXMLElement($requestParams);
} catch (\Exception $e) {
$xml = null;
}
$body = (!is_null($xml) && !empty($xml->xpath('//SOAP-ENV:Body')[0])) ? $xml->xpath('//SOAP-ENV:Body')[0] : [];
return json_decode(json_encode((array)$body), true);
}
function getProviderReferenceCode($response)
{
$response = parseReservationResponseXML($response);
if (!empty($response['OTA_HotelResNotifRS']) && !array_key_exists('Success', $response['OTA_HotelResNotifRS'])) {
return false;
}
$providerReferenceCode = (isset($response['OTA_HotelResNotifRS']['HotelReservations']['HotelReservation']['ResGlobalInfo']['HotelReservationIDs']['HotelReservationID']['@attributes']['ResID_Value']))
? $response['OTA_HotelResNotifRS']['HotelReservations']['HotelReservation']['ResGlobalInfo']['HotelReservationIDs']['HotelReservationID']['@attributes']['ResID_Value']
: false;
if (!$providerReferenceCode) {
return false;
}
return $providerReferenceCode;
}
var_dump(getProviderReferenceCode($xml));