-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgetpages.php
33 lines (26 loc) · 921 Bytes
/
getpages.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
<?php
function get_http_response_code($url)
{
$headers = get_headers($url);
return substr($headers[0], 9, 3);
}
$create_url = "http://www.shiksha.com/b-tech/colleges/b-tech-colleges-". $_GET["city_name"] ;
if( get_http_response_code($create_url) != "200")
{
$json = [['error' => 1]];
header("Content-type: application/json");
print(json_encode($json, JSON_PRETTY_PRINT));
}
else
{
$data = file_get_contents($create_url);
//finding the number of pages
$page = '@(\d)</a></li>\s*<li class="next linkpagination">@';
if(!preg_match($page, $data, $pages))
$pages[1] = 1;
//print($pages[1]);
$json = [['pages' => $pages[1], 'error' => 0]];
header("Content-type: application/json");
print(json_encode($json, JSON_PRETTY_PRINT));
}
?>