-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.php
57 lines (46 loc) · 1.46 KB
/
api.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
<?php
if(hasParam('query'))
{
header('Content-Type: application/json');
$cab = strtoupper($_REQUEST['query']);
$csv = "https://raw.githubusercontent.com/WokeWorld/Australia-Telstra-Payphone-Number-Database/main/full-telstra-phonebox-database.csv";
$lines = file($csv);
$responseArr = array();
$count = 0;
foreach($lines as $line) {
if(strpos($line,$cab) !== false)
{
$items = explode('"',trim($line));
$cid = str_replace(",","",trim($items[0]));
$loc = trim(str_replace(',',"",trim($items[1])));
$pc = trim(str_replace(',',"",trim($items[2])));
$st = trim(str_replace(',',"",trim($items[4])));
$addr = str_replace(' '," ",($loc.", ".$st.", ".$pc));
$ph = trim($items[5]);
$responseArr[$count] = array(
"Cabinet ID" => $cid,
"Address" => $addr ,
"Number" => $ph
);
$count++;
}
}
header("HTTP/1.1 200 OK");
http_response_code(200);
echo json_encode($responseArr,JSON_PRETTY_PRINT);
exit();
}
else
{
header("HTTP/1.1 300 ERROR");
http_response_code(300);
echo json_encode(array(
"Error" => "Invalid Query Provided",
),JSON_PRETTY_PRINT);
exit();
}
function hasParam($param)
{
return array_key_exists($param, $_REQUEST);
}
?>