Last active
January 20, 2016 13:54
-
-
Save hakre/5585567 to your computer and use it in GitHub Desktop.
Expedia PHP SimpleXML API Code Example - See as well http://stackoverflow.com/a/16568432/367456
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<ns2:HotelListResponse xmlns:ns2="http://v3.hotel.wsapi.ean.com/"> | |
<?xml-stylesheet type="text/xsl" href="css/stile.xsl"?> | |
<customerSessionId>... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Some little $_POST values and $apiKey are already set. | |
*/ | |
$_POST['datepicker1'] = '2013-06-12'; | |
$_POST['datepicker2'] = '2013-06-16'; | |
$apiKey = '.....'; | |
$destination = 'napoli'; | |
$adults = '2'; | |
/* | |
* Create the XML for the request with hepl of SimpleXML | |
*/ | |
$url = "https://api.eancdn.com/ean-services/rs/hotel/v3/list"; | |
$xml = new SimpleXMLElement('<HotelListRequest/>'); | |
$xml->destinationString = $destination; | |
$xml->arrivalDate = $_POST['datepicker1']; | |
$xml->departureDate = $_POST['datepicker2']; | |
$xml->RoomGroup->Room->numberOfAdults = $adults; | |
/* | |
* Set the parameters for the API request | |
*/ | |
$params = [ | |
'cid' => 55505, | |
'minorRev' => 99, | |
'apiKey' => $apiKey, | |
'locale' => 'it_IT', | |
'currencyCode' => 'EUR', | |
'xml' => $xml->asXML(), | |
]; | |
/* | |
* Set the stream context for the API request | |
*/ | |
$context = stream_context_create(['http' => [ | |
'method' => 'POST', | |
'header' => [ | |
'Accept: application/xml', | |
'Content-Type: application/x-www-form-urlencoded', | |
], | |
'content' => http_build_query($params), | |
]]); | |
libxml_set_streams_context($context); | |
/* | |
* Perform the API request (and here: insert the stylesheet PI) | |
*/ | |
$hotel = simplexml_load_file($url, 'MySimpleXMLElement'); | |
$hotel->addProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="css/stile.xsl"'); | |
$hotel->asXML('php://output'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment