php 取xml中的資料 -超級簡略-

來源:互聯網
上載者:User
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
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.