OebbApiWeb/suggest.php

37 lines
1.4 KiB
PHP
Raw Permalink Normal View History

2025-07-05 21:24:53 +02:00
<?php
if(!empty($_GET['name']) && strlen($_GET['name'])>2) {
$type = $_GET['type'];
//http://fahrplan.oebb.at/bin/ajax-getstop.exe/dn?REQ0JourneyStopsS0A=1&REQ0JourneyStopsB=12&S=""&js=true
$name = urldecode($_GET['name']);
$ch = curl_init();
$buffer = "";
curl_setopt($ch, CURLOPT_URL, 'https://fahrplan.oebb.at/bin/ajax-getstop.exe/dn?REQ0JourneyStopsS0A=1&REQ0JourneyStopsB=12&S='.$name.'&js=true');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_HEADER, false);
$fh=curl_exec($ch);
//var_dump(curl_getinfo($ch));
// schließe den cURL-Handle und gebe die Systemresourcen frei
curl_close($ch);
if ($fh) {
$buffer = trim($fh);
}
$data = json_decode(mb_convert_encoding(str_replace("SLs.sls={\"suggestions\":","",str_replace("};SLs.showSuggestion();","",$buffer)),'UTF-8','ISO-8859-1'));
if($type=="station") {
$output = '<datalist id="listit">';
foreach ($data as $value) {
$output .= '<option value="' . $value->{"extId"} . '">' . $value->{"value"} . '</option>';
}
$output .= '</datalist>';
echo $output;
}else{
$output = '<datalist id="liststations">';
foreach ($data as $value) {
$output .= '<option>' . $value->{"value"} . '</option>';
}
$output .= '</datalist>';
echo $output;
}
}