-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch.php
169 lines (80 loc) · 2.91 KB
/
fetch.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
// Step 1: Define the JSON file or API URL
$pincode = $_POST['pin'];
$apiUrl = 'https://api.postalpincode.in/pincode/'; // Replace with the actual file path or API endpoint
$full_url = $apiUrl.$pincode;
// Step 2: Fetch the JSON data
$jsonData = file_get_contents($full_url);
// Step 3: Decode the JSON data into a PHP array
$data = json_decode($jsonData, true);
// Check if data is valid
if (!isset($data[0]['PostOffice'])) {
die('Invalid JSON data');
}
// Step 4: Extract the PostOffice array
$postOffices = $data[0]['PostOffice'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Post Office Data</title>
<style>
table {
border-collapse: collapse;
width: 100%;
margin: 20px 0;
font-family: Arial, sans-serif;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #f4f4f4;
}
tr:nth-child(even) {
background-color: #f9f9f9;
}
</style>
</head>
<body>
<h1>Post Office Data</h1>
<table>
<thead>
<tr>
<th>Name</th>
<th>Branch Type</th>
<th>Delivery Status</th>
<th>Circle</th>
<th>District</th>
<th>Division</th>
<th>Region</th>
<th>Block</th>
<th>State</th>
<th>Country</th>
<th>Pincode</th>
</tr>
</thead>
<tbody>
<?php foreach ($postOffices as $postOffice): ?>
<tr>
<td><?= htmlspecialchars($postOffice['Name']) ?></td>
<td><?= htmlspecialchars($postOffice['BranchType']) ?></td>
<td><?= htmlspecialchars($postOffice['DeliveryStatus']) ?></td>
<td><?= htmlspecialchars($postOffice['Circle']) ?></td>
<td><?= htmlspecialchars($postOffice['District']) ?></td>
<td><?= htmlspecialchars($postOffice['Division']) ?></td>
<td><?= htmlspecialchars($postOffice['Region']) ?></td>
<td><?= htmlspecialchars($postOffice['Block']) ?></td>
<td><?= htmlspecialchars($postOffice['State']) ?></td>
<td><?= htmlspecialchars($postOffice['Country']) ?></td>
<td><?= htmlspecialchars($postOffice['Pincode']) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</body>
</html>