forked from saaiful/postcode-bd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbdpostcode.php
More file actions
30 lines (28 loc) · 782 Bytes
/
Copy pathbdpostcode.php
File metadata and controls
30 lines (28 loc) · 782 Bytes
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
<?php
for ($i=1; $i < 8; $i++)
{
$html = file_get_contents('http://www.bangladeshpost.gov.bd/PostCodeList.asp?DivID='.$i);
preg_match_all('/SubOffice.*\n\s+([A-Za-z]+)/', $html, $d);
preg_match_all('/<td><div align="center"><font size="2" face="Arial, Helvetica, sans-serif">(.*)<\/font><\/div><\/td>/', $html, $match);
$datas = array_chunk($match[1],4);
foreach ($datas as $key => $data)
{
$x['division'] = $d[1][0];
$x['district'] = $data[0];
$x['thana'] = $data[1];
$x['suboffice'] = $data[2];
$x['postcode'] = $data[3];
$postCode[] = $x;
}
}
var_dump(count($postCode));
function makeCSV($datas)
{
foreach ($datas as $key => $data)
{
$x[] = implode(",", $data);
}
return implode("\n", $x);
}
file_put_contents('postcode.csv',makeCSV($postCode));
?>