PHP获取API接口的XML数据

版权声明:有问题可联系博主QQ:15577969,大家一起相互交流和学习。 https://blog.csdn.net/qq15577969/article/details/81014984
<?php
header('Content-Type:text/html; charset=utf-8');
//1.获取xml数据 
$xmldata=file_get_contents("http://api网址");
//2.把xml转换为simplexml对象
//$xmlstring=simplexml_load_string($xmldata);
$xmlstring = simplexml_load_string($xmldata, 'SimpleXMLElement', LIBXML_NOCDATA); 
//3.把simplexml对象转换成 json,再将 json 转换成数组。
$value_array = json_decode(json_encode($xmlstring),true); 
//print_r($value_array);
//die();
$result =$value_array['row'];
//期号
$expect = $result['@attributes']['expect'];
//号码
$opencode = $result['@attributes']['opencode'];
//时间
$opentime = $result['@attributes']['opentime'];
//print_r($expect."-".$opencode."-".$opentime);
//die();
?>

猜你喜欢

转载自blog.csdn.net/qq15577969/article/details/81014984