Rumah > pembangunan bahagian belakang > tutorial php > php 取xml中的数据 --超级简单---急急

php 取xml中的数据 --超级简单---急急

WBOY
Lepaskan: 2016-06-23 14:22:58
asal
773 orang telah melayarinya

数据源: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));
Salin selepas log masuk
Salin selepas log masuk
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);
Salin selepas log masuk
Salin selepas log masuk
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|05
[opentime] => 2013-09-15 21:30:00
[ballsnum] => 2
)

[6] => Array
(
[expect] => 13107
[opencode] => 07,09,11,17,28,31|11
[opentime] => 2013-09-12 21:30:00
[ballsnum] => 3
)

[7] => Array
(
[expect] => 13106
[opencode] => 09,11,23,30,31,32|06
[opentime] => 2013-09-10 21:30:00
[ballsnum] => 3
)

[8] => Array
(
[expect] => 13105
[opencode] => 01,11,23,27,31,32|09
[opentime] => 2013-09-08 21:30:00
[ballsnum] => 4
)

[9] => Array
(
[expect] => 13104
[opencode] => 01,02,04,15,17,28|11
[opentime] => 2013-09-05 21:30:00
[ballsnum] => 1
)

[10] => Array
(
[expect] => 13103
[opencode] => 02,04,09,13,18,20|07
[opentime] => 2013-09-03 21:30:00
[ballsnum] => 3
)

[11] => Array
(
[expect] => 13102
[opencode] => 02,04,05,06,08,16|03
[opentime] => 2013-09-01 21:30:00
[ballsnum] => 2
)

[12] => Array
(
[expect] => 13101
[opencode] => 05,07,09,23,27,32|01
[opentime] => 2013-08-29 21:30:00
[ballsnum] => 3
)

[13] => Array
(
[expect] => 13100
[opencode] => 04,08,11,14,16,20|11
[opentime] => 2013-08-27 21:30:00
[ballsnum] => 3
)

[14] => Array
(
[expect] => 13099
[opencode] => 05,11,20,21,26,31|03
[opentime] => 2013-08-25 21:30:00
[ballsnum] => 1
)

[15] => Array
(
[expect] => 13098
[opencode] => 07,15,18,19,20,26|14
[opentime] => 2013-08-22 21:30:00
[ballsnum] => 2
)

[16] => Array
(
[expect] => 13097
[opencode] => 05,14,17,22,23,25|07
[opentime] => 2013-08-20 21:30:00
[ballsnum] => 2
)

[17] => Array
(
[expect] => 13096
[opencode] => 01,02,22,28,29,30|15
[opentime] => 2013-08-18 21:30:00
[ballsnum] => 4
)

[18] => Array
(
[expect] => 13095
[opencode] => 01,06,15,19,28,29|10
[opentime] => 2013-08-15 21:30:00
[ballsnum] => 1
)

[19] => Array
(
[expect] => 13094
[opencode] => 02,04,14,18,20,22|07
[opentime] => 2013-08-13 21:30:00
[ballsnum] => 3
)

[20] => Array
(
[expect] => 13093
[opencode] => 01,02,08,26,29,31|14
[opentime] => 2013-08-11 21:30:00
[ballsnum] => 4
)

[21] => Array
(
[expect] => 13092
[opencode] => 07,11,15,21,26,31|06
[opentime] => 2013-08-08 21:30:00
[ballsnum] => 2
)

[22] => Array
(
[expect] => 13091
[opencode] => 04,14,24,25,28,31|10
[opentime] => 2013-08-06 21:30:00
[ballsnum] => 4
)

[23] => Array
(
[expect] => 13090
[opencode] => 02,05,11,23,24,29|08
[opentime] => 2013-08-04 21:30:00
[ballsnum] => 4
)

[24] => Array
(
[expect] => 13089
[opencode] => 04,08,12,19,21,25|13
[opentime] => 2013-08-01 21:30:00
[ballsnum] => 4
)

[25] => Array
(
[expect] => 13088
[opencode] => 09,15,20,21,22,24|14
[opentime] => 2013-07-30 21:30:00
[ballsnum] => 3
)

[26] => Array
(
[expect] => 13087
[opencode] => 02,13,19,23,24,28|05
[opentime] => 2013-07-28 21:30:00
[ballsnum] => 3
)

[27] => Array
(
[expect] => 13086
[opencode] => 02,04,11,13,16,26|11
[opentime] => 2013-07-25 21:30:00
[ballsnum] => 4
)

[28] => Array
(
[expect] => 13085
[opencode] => 02,08,12,14,16,32|16
[opentime] => 2013-07-23 21:30:00
[ballsnum] => 4
)

[29] => Array
(
[expect] => 13084
[opencode] => 05,07,09,11,20,21|03
[opentime] => 2013-07-21 21:30:00
[ballsnum] => 2
)

)

$url = 'http://www.caipiaokong.com/api/lottery/xml.php?type=ssq';$ar = file($url);print_r(array_slice($ar, 2, 3));
Salin selepas log masuk
Salin selepas log masuk
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);
Salin selepas log masuk
Salin selepas log masuk
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|05
            [opentime] => 2013-09-15 21:30:00
            [ballsnum] => 2
        )

    [6] => Array
        (
            [expect] => 13107
            [opencode] => 07,09,11,17,28,31|11
            [opentime] => 2013-09-12 21:30:00
            [ballsnum] => 3
        )

    [7] => Array
        (
            [expect] => 13106
            [opencode] => 09,11,23,30,31,32|06
            [opentime] => 2013-09-10 21:30:00
            [ballsnum] => 3
        )

    [8] => Array
        (
            [expect] => 13105
            [opencode] => 01,11,23,27,31,32|09
            [opentime] => 2013-09-08 21:30:00
            [ballsnum] => 4
        )

    [9] => Array
        (
            [expect] => 13104
            [opencode] => 01,02,04,15,17,28|11
            [opentime] => 2013-09-05 21:30:00
            [ballsnum] => 1
        )

    [10] => Array
        (
            [expect] => 13103
            [opencode] => 02,04,09,13,18,20|07
            [opentime] => 2013-09-03 21:30:00
            [ballsnum] => 3
        )

    [11] => Array
        (
            [expect] => 13102
            [opencode] => 02,04,05,06,08,16|03
            [opentime] => 2013-09-01 21:30:00
            [ballsnum] => 2
        )

    [12] => Array
        (
            [expect] => 13101
            [opencode] => 05,07,09,23,27,32|01
            [opentime] => 2013-08-29 21:30:00
            [ballsnum] => 3
        )

    [13] => Array
        (
            [expect] => 13100
            [opencode] => 04,08,11,14,16,20|11
            [opentime] => 2013-08-27 21:30:00
            [ballsnum] => 3
        )

    [14] => Array
        (
            [expect] => 13099
            [opencode] => 05,11,20,21,26,31|03
            [opentime] => 2013-08-25 21:30:00
            [ballsnum] => 1
        )

    [15] => Array
        (
            [expect] => 13098
            [opencode] => 07,15,18,19,20,26|14
            [opentime] => 2013-08-22 21:30:00
            [ballsnum] => 2
        )

    [16] => Array
        (
            [expect] => 13097
            [opencode] => 05,14,17,22,23,25|07
            [opentime] => 2013-08-20 21:30:00
            [ballsnum] => 2
        )

    [17] => Array
        (
            [expect] => 13096
            [opencode] => 01,02,22,28,29,30|15
            [opentime] => 2013-08-18 21:30:00
            [ballsnum] => 4
        )

    [18] => Array
        (
            [expect] => 13095
            [opencode] => 01,06,15,19,28,29|10
            [opentime] => 2013-08-15 21:30:00
            [ballsnum] => 1
        )

    [19] => Array
        (
            [expect] => 13094
            [opencode] => 02,04,14,18,20,22|07
            [opentime] => 2013-08-13 21:30:00
            [ballsnum] => 3
        )

    [20] => Array
        (
            [expect] => 13093
            [opencode] => 01,02,08,26,29,31|14
            [opentime] => 2013-08-11 21:30:00
            [ballsnum] => 4
        )

    [21] => Array
        (
            [expect] => 13092
            [opencode] => 07,11,15,21,26,31|06
            [opentime] => 2013-08-08 21:30:00
            [ballsnum] => 2
        )

    [22] => Array
        (
            [expect] => 13091
            [opencode] => 04,14,24,25,28,31|10
            [opentime] => 2013-08-06 21:30:00
            [ballsnum] => 4
        )

    [23] => Array
        (
            [expect] => 13090
            [opencode] => 02,05,11,23,24,29|08
            [opentime] => 2013-08-04 21:30:00
            [ballsnum] => 4
        )

    [24] => Array
        (
            [expect] => 13089
            [opencode] => 04,08,12,19,21,25|13
            [opentime] => 2013-08-01 21:30:00
            [ballsnum] => 4
        )

    [25] => Array
        (
            [expect] => 13088
            [opencode] => 09,15,20,21,22,24|14
            [opentime] => 2013-07-30 21:30:00
            [ballsnum] => 3
        )

    [26] => Array
        (
            [expect] => 13087
            [opencode] => 02,13,19,23,24,28|05
            [opentime] => 2013-07-28 21:30:00
            [ballsnum] => 3
        )

    [27] => Array
        (
            [expect] => 13086
            [opencode] => 02,04,11,13,16,26|11
            [opentime] => 2013-07-25 21:30:00
            [ballsnum] => 4
        )

    [28] => Array
        (
            [expect] => 13085
            [opencode] => 02,08,12,14,16,32|16
            [opentime] => 2013-07-23 21:30:00
            [ballsnum] => 4
        )

    [29] => Array
        (
            [expect] => 13084
            [opencode] => 05,07,09,11,20,21|03
            [opentime] => 2013-07-21 21:30:00
            [ballsnum] => 2
        )

) 这个不是很好呀,我要的是前3期的内容,并能提取具体的数据,比如期号,号码,开奖时间,这样子的

1.期号:
号码:
开奖时间:
2.期号:
号码:
开奖时间:
3.期号:
号码:
开奖时间:
上面这个样子的

可以了,第二个自己稍微改动一下就好了,谢谢斑竹啊

sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan