想抓疾管確診資料(這是json沒錯吧...XD:
https://covid19dashboard.cdc.gov.tw/dash3
求各位大神解答
code
<?php
$url = "https://covid19dashboard.cdc.gov.tw/dash3";
$resutlt1 = file_get_contents($url);
$resutlt1_json = json_decode($resutlt1, true);
print_r("確診: ".$resutlt1_json[0]["確診"]);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result2 = curl_exec($ch);
$result2_json = json_decode($result2, true);
print_r("\n送驗: ".$result2_json[0]["送驗"]);
curl_close($ch);
result
確診: 467
送驗: 81,167
兩種方法自己挑
明明問問題簡潔有力,怎麼就不會敘述問題...
<?php
$data = file_get_contents('https://covid19dashboard.cdc.gov.tw/dash3');
print_r(json_decode($data,true));
// output: Array ( [0] => Array ( [確診] => 467 [解除隔離] => 441 [死亡] => 7 [送驗] => 81,167 [排除] => 80,105 [昨日確診] => 5 [昨日排除] => 320 [昨日送驗] => 344 ) )
如果你還問我說要怎麼處理 array 的資料的話....
請好好修習PHP吧!