3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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));
based on bcevh
Output for 5.6.0 - 5.6.30, 7.0.0 - 7.2.6
Warning: SimpleXMLElement::__construct(): Entity: line 2: parser error : XML declaration allowed only at the start of the document in /in/qen88 on line 35 Warning: SimpleXMLElement::__construct(): <?xml version="1.0" encoding="UTF-8" ?> in /in/qen88 on line 35 Warning: SimpleXMLElement::__construct(): ^ in /in/qen88 on line 35 Warning: SimpleXMLElement::__construct(): namespace error : xmlns:xsd: 'http://www.opentravel.org/OTA/2003/05 OTA_HotelResNotifRQ.xsd' is not a valid URI in /in/qen88 on line 35 Warning: SimpleXMLElement::__construct(): tance" xmlns:xsd="http://www.opentravel.org/OTA/2003/05 OTA_HotelResNotifRQ.xsd" in /in/qen88 on line 35 Warning: SimpleXMLElement::__construct(): ^ in /in/qen88 on line 35 bool(false)
Output for hhvm-3.12.14 - 3.22.0
bool(false) Entity: line 2: parser error : XML declaration allowed only at the start of the document <?xml version="1.0" encoding="UTF-8" ?> ^ namespace error : xmlns:xsd: 'http://www.opentravel.org/OTA/2003/05 OTA_HotelResNotifRQ.xsd' is not a valid URI tance" xmlns:xsd="http://www.opentravel.org/OTA/2003/05 OTA_HotelResNotifRQ.xsd" ^