Using SimpleXML to load remote URL

后端 未结 1 1702
不思量自难忘°
不思量自难忘° 2020-12-01 16:21

I am trying to use SimpleXML to load a remote URL.

If I type into my browser the following;

http://api.ean.com/ean-services/rs/hotel/v3/list?cid=555         


        
相关标签:
1条回答
  • 2020-12-01 17:00

    The results are coming back as json. Replace simplexml_load_file with json_decode and you will see a proper object.

    If you want to use xml, you need to specify it in the headers. The following code will return valid xml:

    $context  = stream_context_create(array('http' => array('header' => 'Accept: application/xml')));
    $url = 'http://api.ean.com/ean-services/rs/hotel/v3/list?cid=55505&minorRev=12&apiKey=2hkhej72gxyas3ky6hhjtsga&locale=en_US&currencyCode=USD&customerIpAddress=10.184.2.9&customerSessionId=&xml=<HotelListRequest><arrivalDate>01/22/2012</arrivalDate><departureDate>01/24/2012</departureDate><RoomGroup><Room><numberOfAdults>1</numberOfAdults><numberOfChildren>1</numberOfChildren><childAges>4</childAges></Room></RoomGroup><city>Amsterdam</city><countryCode>NL</countryCode><supplierCacheTolerance>MED</supplierCacheTolerance></HotelListRequest> ';
    
    $xml = file_get_contents($url, false, $context);
    $xml = simplexml_load_string($xml);
    print_r($xml);
    ?>
    
    0 讨论(0)
提交回复
热议问题