php抓取這個網頁的資料,只要資料,不用html內容,然後json後寫入檔案,新手求教

來源:互聯網
上載者:User
php抓取這個網頁的資料,只要資料,不要html內容,然後json後寫入檔案,新手求教
http://www.okooo.com/Upload/sohu/table_23.html
新收求教啊,這個難度在於正則上,不會寫正則啊
------解決方案--------------------
$url = 'http://www.okooo.com/Upload/sohu/table_23.html';
$s = file_get_contents($url);
preg_match_all('##isU', $s, $m);
foreach(array_map('strip_tags', $m[0]) as $r) {
$a = preg_split('/\s+/', $r, -1, PREG_SPLIT_NO_EMPTY);
$res[] = array_chunk(array_slice($a, 0, -1), 3);
}
print_r($res);
echo json_encode($res);
Array
(
[0] => Array
(
[0] => Array
(
[0] => 排名
[1] => 球隊
[2] => 積分
)

[1] => Array
(
[0] => 1
[1] => 尤文圖斯
[2] => 102
)

[2] => Array
(
[0] => 2
[1] => 羅馬
[2] => 85
)

[3] => Array
(
[0] => 3
[1] => 那不勒斯
[2] => 78
)

[4] => Array
(
[0] => 4
[1] => 佛羅倫薩
[2] => 65
)

[5] => Array
(
[0] => 5
[1] => 國際米蘭
[2] => 60
)

[6] => Array
(
[0] => 6
[1] => 帕爾馬
[2] => 58
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.