1<?php 2header('Content-Type:text/html; charset=utf-8'); 3//1.获取xml数据 4$xmldata=file_get_contents("http://api网址"); 5//2.把xml转换为simplexml对象 6//$xmlstring=simplexml_load_string($xmldata); 7$xmlstring = simplexml_load_string($xmldata, 'SimpleXMLElement', LIBXML_NOCDATA); 8//3.把simplexml对象转换成 json,再将 json 转换成数组。 9$value_array = json_decode(json_encode($xmlstring),true); 10//print_r($value_array); 11//die(); 12$result =$value_array['row']; 13//期号 14$expect = $result['@attributes']['expect']; 15//号码 16$opencode = $result['@attributes']['opencode']; 17//时间 18$opentime = $result['@attributes']['opentime']; 19//print_r($expect."-".$opencode."-".$opentime); 20//die(); 21?>
PHP获取API接口XML数据
Wesley13
2021-10-11
1258 0 0
点赞
收藏
评论区
加载中...