-
Notifications
You must be signed in to change notification settings - Fork 0
/
streets.php
64 lines (56 loc) · 2.06 KB
/
streets.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
<?php
header("Content-Type: text/html; charset=windows-1255");
/*
*Import all Israeli streets.
*license: https://data.gov.il/terms
*/
$filename = "https://data.gov.il/dataset/321/resource/a7296d1a-f8c9-4b70-96c2-6ebb4352f8e3/download";
$handle = fopen($filename, "r");
/*
*Import all streets in city code.
*@param cityCode : String, 4 digits.
*return sorted array by key:
*array: "XXXXXXXX" => array("cityCode"=>XXXX, "cityName"=>"hebrew name" "streetCode"=>XXXX, "streetName"=>"hebrew name")
*/
function importStreets($cityCode) {
$data = array();
if ($GLOBALS["handle"]) {
while (($line = fgetcsv($GLOBALS["handle"])) !== false) {
if (sprintf("%04d\n", $line[1]) == $cityCode) {
$identify = rtrim(sprintf("%04d\n", $line[1])).ltrim(sprintf("%04d\n", $line[3]));
$data[$identify] = array("cityCode"=>$line[1], "cityName"=>$line[2], "streetCode"=>$line[3], "streetName"=>$line[4]);
}
}
fclose($GLOBALS["handle"]);
ksort($data); //sort the array by identify key
} else {
return 0; //error read file
}
return $data;
}
/*
*Import all streets in file.
*return array: "XXXXXXXX" => array("cityCode"=>XXXX, "cityName"=>"hebrew name" "streetCode"=>XXXX, "streetName"=>"hebrew name")
*/
function importAll() {
$row = 1;
$data = array();
if ($GLOBALS["handle"]) {
while (($line = fgetcsv($GLOBALS["handle"])) !== false) {
if ($row == 1 || $row == 2) { $row++; continue; } //skip rows 1 and 2.
$identify = rtrim(sprintf("%04d\n", $line[1])).ltrim(sprintf("%04d\n", $line[3]));
$data[$identify] = array("cityCode"=>$line[1], "cityName"=>$line[2], "streetCode"=>$line[3], "streetName"=>$line[4]);
$row++;
}
fclose($GLOBALS["handle"]);
} else {
return 0; //error read file
}
return $data;
}
function printData($data) {
foreach ($data as $key => $val) {
echo $key." => ".$val["streetName"].", ".$val["cityName"]."<br>";
}
}
?>