<?php
//第一种办法:
$url = "https://api.map.baidu.com/telematics/v2/distance?waypoints=116.551016,39.915544;116.605777,39.914824&ak=1a3cde429f38434f1811a75e1a90310c";
$result = httpGet($url);
return $result;
//第二种方法:
$data_xml = file_get_contents($url);
$dom = new DomDocument;
$dom->loadXML($data_xml);
$data_json = json_encode(simplexml_import_dom($dom));
echo $data_json;
//第三种方法:
ceshi.xml:
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[FromUser]]></FromUserName>
<CreateTime>123456789</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[subscribe]]></Event>
</xml>
read.php:
//$xmldata=file_get_contents("php://input");
$path = 'ceshi.xml';
$xml = simplexml_load_file($path);
$data = [];
foreach($xml->children() as $key=>$value){
$data[(string)$key] = (string)$value;
}
dump($data);die;
//第四种方法:
$path = '<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[FromUser]]></FromUserName>
<CreateTime>123456789</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[subscribe]]></Event>
</xml>';
$xml = simplexml_load_string($path);
$data = [];
foreach($xml->children() as $key=>$value){
$data[(string)$key] = (string)$value;
}
dump($data);die;