1 |
torben |
300 |
<? |
2 |
|
|
|
3 |
|
|
function download($url) |
4 |
|
|
{ |
5 |
|
|
$temp_buffer = file_get_contents($url); |
6 |
|
|
|
7 |
|
|
$buffer = str_replace("\"", "'", $temp_buffer); |
8 |
|
|
return $buffer; |
9 |
|
|
} |
10 |
|
|
|
11 |
|
|
function stationList() |
12 |
|
|
{ |
13 |
|
|
$stations = array(); |
14 |
|
|
|
15 |
|
|
$url = "http://www.bane.dk/visStationsliste.asp?artikelID=4277"; |
16 |
|
|
$buffer = download($url); |
17 |
|
|
|
18 |
|
|
$pos = 0; |
19 |
|
|
$pos = stripos($buffer, "<td class='Oversigt'>"); |
20 |
|
|
$sverige = stripos($buffer, "Sverige"); |
21 |
|
|
$s_tog = stripos($buffer, "<b>S-tog</b>"); |
22 |
|
|
|
23 |
|
|
while (1) { |
24 |
|
|
|
25 |
|
|
$pos = stripos($buffer, "W=", $pos); |
26 |
|
|
|
27 |
|
|
if ($pos == FALSE) |
28 |
|
|
break; |
29 |
|
|
|
30 |
|
|
if ($pos >= $sverige && $pos<$s_tog) { |
31 |
|
|
$pos = $s_tog; |
32 |
|
|
continue; |
33 |
|
|
} |
34 |
|
|
|
35 |
|
|
$stationEnd = stripos($buffer, "'>", $pos); |
36 |
|
|
|
37 |
|
|
$statStr = substr($buffer,$pos, $stationEnd-$pos); |
38 |
|
|
$pos++; |
39 |
|
|
|
40 |
|
|
$pairs = split("&", $statStr); |
41 |
|
|
|
42 |
|
|
|
43 |
|
|
$entry = array(); |
44 |
|
|
foreach ($pairs as $pair) { |
45 |
|
|
$tmppair = split("=", $pair); |
46 |
|
|
$key = strtolower($tmppair[0]); |
47 |
|
|
if ($key == "artikelid") |
48 |
|
|
continue; |
49 |
|
|
$entry[ $key ] = $tmppair[1]; |
50 |
|
|
} |
51 |
|
|
|
52 |
|
|
$stations[] = $entry; |
53 |
|
|
|
54 |
|
|
|
55 |
|
|
} |
56 |
|
|
return $stations; |
57 |
|
|
} |
58 |
|
|
|
59 |
|
|
function lastUpdateString( $updateCode ) |
60 |
|
|
{ |
61 |
|
|
switch( $updateCode ) |
62 |
|
|
{ |
63 |
|
|
case '1': |
64 |
|
|
$result = "< 3 min"; |
65 |
|
|
break; |
66 |
|
|
case '2': |
67 |
|
|
$result = "3 - 10 min"; |
68 |
|
|
break; |
69 |
|
|
case '3': |
70 |
|
|
$result = ">10 min"; |
71 |
|
|
break; |
72 |
|
|
case '4': |
73 |
|
|
$result = "No info"; |
74 |
|
|
break; |
75 |
|
|
default: |
76 |
|
|
$result = "Unknown:" . $buffer[$pos]; |
77 |
|
|
} |
78 |
|
|
|
79 |
|
|
return $result; |
80 |
|
|
} |
81 |
|
|
|
82 |
|
|
function tog3($search) |
83 |
|
|
{ |
84 |
|
|
$result = array(); |
85 |
|
|
|
86 |
|
|
$current = tog("FJRN", $search, ""); |
87 |
|
|
$result2 = array_merge($result,$current); |
88 |
|
|
$result = $result2; |
89 |
|
|
|
90 |
|
|
$current = tog("S2", $search, ""); |
91 |
|
|
$result2 = array_merge($result,$current); |
92 |
|
|
$result = $result; |
93 |
|
|
|
94 |
|
|
return $result; |
95 |
|
|
} |
96 |
|
|
|
97 |
|
|
function tog2($search) |
98 |
|
|
{ |
99 |
|
|
// echo "<!-- $search -->\n"; |
100 |
|
|
$result = array(); |
101 |
|
|
|
102 |
|
|
$search = strtolower($search); |
103 |
|
|
$stations = stationList(); |
104 |
|
|
for ($i=0; $i<sizeof($stations); $i++) { |
105 |
|
|
$row = $stations[$i]; |
106 |
|
|
|
107 |
|
|
$type = $row["w"]; |
108 |
|
|
$stationcode = $row["s"]; |
109 |
|
|
$stationname = $row["statnavn"]; |
110 |
|
|
|
111 |
|
|
//echo "<!-- $type $stationcode $stationname -->\n"; |
112 |
|
|
$lcstation = strtolower($stationname); |
113 |
|
|
if ($search == $lcstation || |
114 |
|
|
strpos($search, $lcstation) != FALSE || |
115 |
|
|
strpos($lcstation,$search) != FALSE) |
116 |
|
|
{ |
117 |
|
|
$current = tog($type,$stationcode,$stationname); |
118 |
|
|
$result2 = array_merge($result,$current); |
119 |
|
|
$result = $result2; |
120 |
|
|
} |
121 |
|
|
} |
122 |
|
|
return $result; |
123 |
|
|
} |
124 |
|
|
|
125 |
|
|
|
126 |
|
|
function tog($type, $stationcode, $stationname) |
127 |
|
|
{ |
128 |
|
|
$result = array(); |
129 |
|
|
|
130 |
|
|
$url = "http://www.bane.dk/visStation.asp?W=$type&S=$stationcode&artikelId=4275&statnavn=$stationname"; |
131 |
|
|
|
132 |
|
|
$buffer = download($url); |
133 |
|
|
|
134 |
|
|
|
135 |
|
|
$pos=0; |
136 |
|
|
$ankomstpos = stripos($buffer, "id='ankomsttabel'"); |
137 |
|
|
|
138 |
|
|
$count = 0; |
139 |
|
|
while(1) { |
140 |
|
|
|
141 |
|
|
// start med tid |
142 |
|
|
$pos = stripos($buffer, "<td CLASS='Tid'>", $pos); |
143 |
|
|
|
144 |
|
|
if ($pos == FALSE) |
145 |
|
|
break; |
146 |
|
|
|
147 |
|
|
if ($pos > $ankomstpos) |
148 |
|
|
break; |
149 |
|
|
|
150 |
|
|
$pos = stripos($buffer, "<span", $pos); |
151 |
|
|
|
152 |
|
|
$start = $pos; |
153 |
|
|
$stop = stripos($buffer, "</td>", $pos); |
154 |
|
|
$time = substr($buffer,$start, $stop-$start); |
155 |
|
|
$time = strip_tags($time); |
156 |
|
|
$result[$count][0] = trim($time); |
157 |
|
|
|
158 |
|
|
//Opdaterings-info |
159 |
|
|
$pos = stripos($buffer, "<TD CLASS='opdater'>", $pos); |
160 |
|
|
$pos = stripos($buffer, "src='",$pos); |
161 |
|
|
$pos = stripos($buffer, "opdater",$pos); |
162 |
|
|
$pos += 7; |
163 |
|
|
$result[$count][1] = $buffer[$pos]; |
164 |
|
|
|
165 |
|
|
|
166 |
|
|
// Type |
167 |
|
|
$pos = stripos($buffer, "<TD CLASS='TogType'>", $pos); |
168 |
|
|
$start = $pos + 20; |
169 |
|
|
$stop = stripos($buffer, "</td>", $pos); |
170 |
|
|
$type = substr($buffer, $start, $stop-$start); |
171 |
|
|
$type = strip_tags($type); |
172 |
|
|
$type = str_replace(" ", " ", $type); |
173 |
|
|
$result[$count][2] = $type; |
174 |
|
|
|
175 |
|
|
// Destination |
176 |
|
|
$pos = stripos($buffer, "<TD CLASS='Til'>", $pos); |
177 |
|
|
$start = $pos + 16; |
178 |
|
|
$stop = stripos($buffer,"</td>", $pos); |
179 |
|
|
$destination = substr($buffer, $start, $stop-$start); |
180 |
|
|
$destination = strip_tags($destination); |
181 |
|
|
$destination = str_replace(" ", " ", $destination); |
182 |
|
|
$result[$count][3] = $destination; |
183 |
|
|
|
184 |
|
|
//origin |
185 |
|
|
$pos = stripos($buffer, "<TD CLASS='visikke'>", $pos); |
186 |
|
|
$start = $pos + 20; |
187 |
|
|
$stop = stripos($buffer,"</td>", $pos); |
188 |
|
|
$origin = substr($buffer, $start, $stop-$start); |
189 |
|
|
$origin = strip_tags($origin); |
190 |
|
|
$origin = str_replace(" ", " ", $origin); |
191 |
|
|
$result[$count][4] = $origin; |
192 |
|
|
|
193 |
|
|
//current location |
194 |
|
|
$pos++; //since origin and current use the same search pattern, we must increase the position |
195 |
|
|
//so we don't get origin twice. |
196 |
|
|
$pos = stripos($buffer, "<TD CLASS='visikke'>", $pos); |
197 |
|
|
$start = $pos + 20; |
198 |
|
|
$stop = stripos($buffer,"</td>", $pos); |
199 |
|
|
$current = substr($buffer, $start, $stop-$start); |
200 |
|
|
$current = strip_tags($current); |
201 |
|
|
$current = str_replace(" ", " ", $current); |
202 |
|
|
$result[$count][5] = $current; |
203 |
|
|
|
204 |
|
|
//Status |
205 |
|
|
$pos = stripos($buffer, "<TD CLASS='Status'>", $pos); |
206 |
|
|
$start = $pos + 19; |
207 |
|
|
$stop = stripos($buffer,"</td>", $pos); |
208 |
|
|
$status = substr($buffer, $start, $stop-$start); |
209 |
|
|
$status = str_replace(" ", " ", $status); |
210 |
|
|
$status = strip_tags($status); |
211 |
|
|
$result[$count][6] = $status; |
212 |
|
|
|
213 |
|
|
//note |
214 |
|
|
$pos = stripos($buffer, "<TD CLASS='Bem'>", $pos); |
215 |
|
|
$start = $pos + 16; |
216 |
|
|
$stop = stripos($buffer,"</td>", $pos); |
217 |
|
|
$note = substr($buffer, $start, $stop-$start); |
218 |
|
|
$note = str_replace(" ", " ", $note); |
219 |
|
|
$hasExtraI = stripos($note, ">i<") != FALSE; |
220 |
|
|
$note = strip_tags($note); |
221 |
|
|
if ($hasExtraI) |
222 |
|
|
$note = substr($note,0, strlen($note)-2); |
223 |
|
|
$result[$count][7] = $note; |
224 |
|
|
|
225 |
|
|
$count++; |
226 |
|
|
} |
227 |
|
|
|
228 |
|
|
return $result; |
229 |
|
|
} |
230 |
|
|
|
231 |
|
|
?> |