Created
June 23, 2022 14:08
-
-
Save siteslave/d39f73af4751b54a449a17dc8d5fa814 to your computer and use it in GitHub Desktop.
ดึงข้อมูล Air4Thai ด้วย PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$json = file_get_contents('http://air4thai.pcd.go.th/services/getNewAQI_JSON.php'); | |
$location_json = json_decode($json, true); | |
echo '<table><tr><td>สถานี</td><td>ค่า PM2.5 (µg/m³)</td><td>อัปเดท</td></tr>'; | |
foreach ($location_json['stations'] as $wizard) { | |
$stationName = $wizard['nameTH']; | |
$lastUpdate = $wizard['LastUpdate']; | |
$pm25 = $lastUpdate['PM25']['value']; | |
$pm25Unit = $lastUpdate['PM25']['unit']; | |
$date = $lastUpdate['date']; | |
$time = $lastUpdate['time']; | |
echo '<tr>'; | |
echo '<td>' .$stationName . '</td>'; | |
echo '<td>' . $pm25 . '</td>'; | |
echo '<td>'.' ('.$date.' เวลา '. $time. ')'.'</td>'; | |
echo '</tr>'; | |
} | |
echo '</table>'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment