> 백엔드 개발 > PHP 튜토리얼 > php 取xml中的数据 --超级简单---急急

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

WBOY
풀어 주다: 2016-06-23 14:22:58
원래의
774명이 탐색했습니다.

数据源: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|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));
로그인 후 복사
로그인 후 복사
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|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.期号:
号码:
开奖时间:
上面这个样子的

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

원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿