-
Notifications
You must be signed in to change notification settings - Fork 0
/
mask.php
85 lines (75 loc) · 1.95 KB
/
mask.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
$tit = $_POST["sdropdown"];
$tit2 = $_POST["sdropdown2"];
$url = "https://data.nhi.gov.tw/resource/mask/maskdata.csv";
// FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES
$lines = file($url, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$titles = array_shift($lines);
$titArr = explode(",", $titles);
$tbl = "<table>";
$tbl .= "<tr>";
foreach ($titArr as $title) {
$tbl .= "<th>$title</th>";
}
$tbl .= "</tr>";
foreach ($lines as $line) {
//if (strpos($line, '請選擇鄉鎮') !== false) {
// if (strpos($line, $tit) !== false) {
// $tbl .= "<tr>";
// $dataArr = explode(",", $line);
// foreach ($dataArr as $data) {
// $tbl .= "<td>$data</td>";
// }
// $tbl .= "</tr>";
// }
//}
//else {
if (strpos($line, $tit.$tit2) !== false) {
$tbl .= "<tr>";
$dataArr = explode(",", $line);
foreach ($dataArr as $data) {
$tbl .= "<td>$data</td>";
}
$tbl .= "</tr>";
}
//}
}
$tbl .= "</table>";
?>
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<head>
<meta charset="UTF-8" />
<title>Service Area</title>
<style type="text/css">
table {
border: 3px outset Olive;
margin: 10px auto;
}
tr:nth-of-type(even) {
background-color: LightCyan;
}
td {
padding: 3px 5px;
text-align: right;
}
th {
color: white;
background-color: DarkGreen;
padding: 5px;
}
#cont {
text-align: center;
}
</style>
</head>
<body>
<div id="cont">
<h2>Assignment 7: 口罩剩餘數量即時線上查詢</h2>
<?php
echo $tbl;
?>
</div>
</body>
</html>