php 取xml中的数据 –超级简单—急急
数据源:http://www.caipiaokong.com/api/lottery/xml.php?type=ssq
要取它的前3行数据
——解决方案——————–
$url = 'http://www.caipiaokong.com/api/lottery/xml.php?type=ssq';<br />$ar = file($url);<br />print_r(array_slice($ar, 2, 3));
Array
(
[0] => <row expect="13113" opencode="04,07,11,17,24,33
——解决方案——————–
09″ opentime=”2013-09-26 21:30:00″ ballsnum=”1″ />
[1] => <row expect="13112" opencode="01,06,12,13,22,31
——解决方案——————–
07″ opentime=”2013-09-24 21:30:00″ ballsnum=”1″ />
[2] => <row expect="13111" opencode="01,02,03,06,08,33
——解决方案——————–
13″ opentime=”2013-09-22 21:30:00″ ballsnum=”1″ />
)
$url = 'http://www.caipiaokong.com/api/lottery/xml.php?type=ssq';<br />$xml = sim<i>·本2文来源gaodai$ma#com搞$代*码网2</i><strong>搞gaodaima代码</strong>plexml_load_file($url);<br />foreach($xml->row as $i=>$v) {<br /> if($i > 2) break;<br /> $res[] = current((array)$v->attributes());<br /> <br />}<br />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
转载请注明原文链接:php 取xml中的数据 -超级简略-
