Using SimpleXML to load remote URL

后端 未结 1 1712
不思量自难忘°
不思量自难忘° 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¤cyCode=USD&customerIpAddress=10.184.2.9&customerSessionId=&xml=01/22/201201/24/2012114AmsterdamNLMED ';
    
    $xml = file_get_contents($url, false, $context);
    $xml = simplexml_load_string($xml);
    print_r($xml);
    ?>
    

    0 讨论(0)
提交回复
热议问题