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] => ------解决方案--------------------09" opentime="2013-09-26 21:30:00" ballsnum="1" /> [1] => ------解决方案--------------------07" opentime="2013-09-24 21:30:00" ballsnum="1" /> [2] => ------解决方案--------------------13" opentime="2013-09-22 21:30:00" ballsnum="1" /> ) $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