-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·71 lines (57 loc) · 1.7 KB
/
index.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
<?php
include ("simplehtmldom_1_9_1/simple_html_dom.php");
$html = file_get_html('https://www.mohfw.gov.in/');
$result = [];
$paramValueAllowed = ['state'];
$q = null;
if (array_key_exists('q', $_GET))
{
$q = $_GET['q'];
}
if (!empty($q))
{
if (in_array($q, $paramValueAllowed))
{
if ($q == "state")
{
$head = ['s_no', 'state', 'total_confirmed_case_indian_national', 'total_confirmed_cases_foreign_national', 'cured_discharge_migrated', 'death'];
foreach ($html->find('div#cases') as $e)
{
$i = 1;
foreach ($e->find('div.table-responsive tbody tr') as $trk)
{
$stateWiseData = [];
foreach ($trk->find('td') as $tdk)
{
$stateWiseData[] = $tdk->innertext;
}
$data = [];
foreach ($stateWiseData as $stkey => $stvalue)
{
$data[$head[$stkey]] = $stvalue;
}
$result[] = $data;
$i++;
}
}
$totalElement = count($result);
unset($result[$totalElement - 1]);
unset($result[$totalElement - 2]);
echo json_encode($result, JSON_PRETTY_PRINT);
}
}
else
{
echo json_encode(array(
'status' => 'fail',
'message' => "Please provide the valid value for parameter 'q'."
) , JSON_PRETTY_PRINT);
}
}
else
{
echo json_encode(array(
'status' => 'fail',
'message' => "Please provide the 'q' parameter."
) , JSON_PRETTY_PRINT);
}