PHP获取API接口XML数据


<?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();
?>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM