当前位置:Gxlcms > PHP教程 > php取xml中的数据-超级简略-

php取xml中的数据-超级简略-

时间:2021-07-01 10:21:17 帮助过:11人阅读

php 取xml中的数据 --超级简单---急急
数据源:http://www.caipiaokong.com/api/lottery/xml.php?type=ssq
要取它的前3行数据

分享到:


------解决方案--------------------
$url = 'http://www.caipiaokong.com/api/lottery/xml.php?type=ssq';
$ar = file($url);
print_r(array_slice($ar, 2, 3));
Array
(
[0] =>

[1] =>

[2] =>

)
$url = 'http://www.caipiaokong.com/api/lottery/xml.php?type=ssq';
$xml = simplexml_load_file($url);
foreach($xml->row as $i=>$v) {
if($i > 2) break;
$res[] = current((array)$v->attributes());

}
print_r($res);
Array
(
[0] => Array
(
[expect] => 13113
[opencode] => 04,07,11,17,24,33
------解决方案--------------------
09
[opentime] => 2013-09-26 21:30:00
[ballsnum] => 1
)

[1] => Array
(
[expect] => 13112
[opencode] => 01,06,12,13,22,31
------解决方案--------------------
07
[opentime] => 2013-09-24 21:30:00
[ballsnum] => 1
)

[2] => Array
(
[expect] => 13111
[opencode] => 01,02,03,06,08,33
------解决方案--------------------
13
[opentime] => 2013-09-22 21:30:00
[ballsnum] => 1
)

[3] => Array
(
[expect] => 13110
[opencode] => 15,17,18,21,29,32
------解决方案--------------------
13
[opentime] => 2013-09-19 21:30:00
[ballsnum] => 2
)

[4] => Array
(
[expect] => 13109
[opencode] => 09,23,24,27,29,32
------解决方案--------------------
08
[opentime] => 2013-09-17 21:30:00
[ballsnum] => 3
)

[5] => Array
(
[expect] => 13108
[opencode] => 16,21,22,28,31,32

人气教程排行