private static function parseData($xml, $time, $lang) { $nodes = array(); //var_dump($xml); $i = 0; for ($i = 0; $i < sizeof($xml->VertrekkendeTrein); $i++) { $dep = $xml->VertrekkendeTrein[$i]; $stationNode = stations::getStationFromName($dep->EindBestemming, $lang); $unixtime = strtotime($dep->VertrekTijd); $delay = 0; if (isset($dep->VertrekVertraging)) { $delay = (int) $dep->VertrekVertraging * 60; } $vehicle = "NS.NL." . $dep->TreinSoort; //no ID? $platformNormal = !$dep->VertrekSpoor->wijziging; $vertrekspoor = $dep->VertrekSpoor . " "; $platform = $vertrekspoor; $left = false; $nodes[$i] = new DepartureArrival(); $nodes[$i]->delay = $delay; $nodes[$i]->station = $stationNode; $nodes[$i]->time = $unixtime; $nodes[$i]->vehicle = $vehicle; $nodes[$i]->platform = new Platform(); $nodes[$i]->platform->name = $platform; $nodes[$i]->platform->normal = $platformNormal; $nodes[$i]->left = $left; } return $nodes; }
public static function parseData($xml, $lang) { //<waitingtime><line>5 </line><mode>M </mode><minutes>6 </minutes><destination>Herrma</destination> </waitingtime> preg_match_all("/<waitingtime>.*?<line>(.*?)<\\/line>.*?<mode>(.*?)<\\/mode>.*?<minutes>(.*?)<\\/minutes>.*?<destination>(.*?)<\\/destination>.*?<\\/waitingtime>/si", $xml, $matches); // echo $xml . "\n"; // var_dump($matches); $nodes = array(); for ($i = 1; $i < sizeof($matches[0]); $i++) { $nodes[$i - 1] = new DepartureArrival(); $nodes[$i - 1]->vehicle = "BE.MIVB." . $matches[2][$i] . $matches[1][$i]; $nodes[$i - 1]->time = date("U") + $matches[3][$i] * 60; $nodes[$i - 1]->delay = 0; // echo $matches[3][$i] . " "; try { $nodes[$i - 1]->station = stations::getStationFromName($matches[4][$i], $lang); } catch (Exception $e) { //fallback for if a station is not found $nodes[$i - 1]->station = new Station(); $nodes[$i - 1]->station->id = "notfound"; $nodes[$i - 1]->station->locationX = 0; $nodes[$i - 1]->station->locationY = 0; $nodes[$i - 1]->station->name = $matches[4][$i - 1]; $nodes[$i - 1]->station->standardname = $matches[4][$i - 1]; //echo "No stations found for ". $matches[4][$i-1] . "\n"; } // echo $nodes[$i-1]->station->name; $nodes[$i - 1]->platform = $nodes[$i - 1]->station->name; // echo $i-1 . "\n"; } return $nodes; }
public static function parseHafasXml($serverData, $lang) { $xml = new SimpleXMLElement($serverData); $connection = array(); $i = 0; //DEBUG: echo $serverData ; if (isset($xml->ConRes->ConnectionList->Connection)) { //get stations from & to once for all connections $fromstation = connections::getStationFromHafasLocation($xml->ConRes->ConnectionList->Connection[0]->Overview->Departure->BasicStop->Station['x'], $xml->ConRes->ConnectionList->Connection[0]->Overview->Departure->BasicStop->Station['y'], $lang); $tostation = connections::getStationFromHafasLocation($xml->ConRes->ConnectionList->Connection[0]->Overview->Arrival->BasicStop->Station['x'], $xml->ConRes->ConnectionList->Connection[0]->Overview->Arrival->BasicStop->Station['y'], $lang); foreach ($xml->ConRes->ConnectionList->Connection as $conn) { $connection[$i] = new Connection(); $connection[$i]->departure = new DepartureArrival(); $connection[$i]->arrival = new DepartureArrival(); $connection[$i]->duration = tools::transformDuration($conn->Overview->Duration->Time); $connection[$i]->departure->station = $fromstation; $connection[$i]->departure->time = tools::transformTime($conn->Overview->Departure->BasicStop->Dep->Time, $conn->Overview->Date); $connection[$i]->departure->platform = new Platform(); $connection[$i]->departure->direction = trim($conn->Overview->Departure->BasicStop->Dep->Platform->Text); $connection[$i]->departure->platform->name = trim($conn->Overview->Departure->BasicStop->Dep->Platform->Text); $connection[$i]->arrival->time = tools::transformTime($conn->Overview->Arrival->BasicStop->Arr->Time, $conn->Overview->Date); $connection[$i]->arrival->platform = new Platform(); $connection[$i]->arrival->platform->name = trim($conn->Overview->Arrival->BasicStop->Arr->Platform->Text); $connection[$i]->arrival->station = $tostation; //Delay and platform changes //TODO: get Delay from railtime instead - much better information $delay0 = 0; $delay1 = 0; $platformNormal0 = true; $platformNormal1 = true; if ($conn->RtStateList->RtState["value"] == "HAS_DELAYINFO") { $delay0 = tools::transformTime($conn->Overview->Departure->BasicStop->StopPrognosis->Dep->Time, $conn->Overview->Date) - $connection[$i]->departure->time; if ($delay0 < 0) { $delay0 = 0; } //echo "delay: " .$conn->Overview -> Departure -> BasicStop -> StopPrognosis -> Dep -> Time . "\n"; $delay1 = tools::transformTime($conn->Overview->Arrival->BasicStop->StopPrognosis->Arr->Time, $conn->Overview->Date) - $connection[$i]->arrival->time; if ($delay1 < 0) { $delay1 = 0; } if (isset($conn->Overview->Departure->BasicStop->StopPrognosis->Dep->Platform->Text)) { $platform0 = trim($conn->Overview->Departure->BasicStop->StopPrognosis->Dep->Platform->Text); $platformNormal0 = false; } if (isset($conn->Overview->Arrival->BasicStop->StopPrognosis->Arr->Platform->Text)) { $platform1 = trim($conn->Overview->Arrival->BasicStop->StopPrognosis->Arr->Platform->Text); $platformNormal1 = false; } } $connection[$i]->departure->delay = $delay0; $connection[$i]->departure->platform->normal = $platformNormal0; $connection[$i]->arrival->delay = $delay1; $connection[$i]->arrival->platform->normal = $platformNormal1; $trains = array(); $vias = array(); $directions = array(); $j = 0; $k = 0; $connectionindex = 0; //yay for spaghetti code. if (isset($conn->ConSectionList->ConSection)) { foreach ($conn->ConSectionList->ConSection as $connsection) { if (isset($connsection->Journey->JourneyAttributeList->JourneyAttribute)) { foreach ($connsection->Journey->JourneyAttributeList->JourneyAttribute as $att) { if ($att->Attribute["type"] == "NAME") { $trains[$j] = str_replace(" ", "", $att->Attribute->AttributeVariant->Text); $j++; } else { if ($att->Attribute["type"] == "DIRECTION") { $directions[$k] = stations::getStationFromName(trim($att->Attribute->AttributeVariant->Text), $lang); $k++; } } } if ($conn->Overview->Transfers > 0 && strcmp($connsection->Arrival->BasicStop->Station['name'], $conn->Overview->Arrival->BasicStop->Station['name']) != 0) { //current index for the train: j-1 $departDelay = 0; //Todo: NYImplemented $connarray = $conn->ConSectionList->ConSection; $departTime = tools::transformTime($connarray[$connectionindex + 1]->Departure->BasicStop->Dep->Time, $conn->Overview->Date); $departPlatform = trim($connarray[$connectionindex + 1]->Departure->BasicStop->Dep->Platform->Text); $arrivalTime = tools::transformTime($connsection->Arrival->BasicStop->Arr->Time, $conn->Overview->Date); $arrivalPlatform = trim($connsection->Arrival->BasicStop->Arr->Platform->Text); $arrivalDelay = 0; //Todo: NYImplemented $vias[$connectionindex] = new Via(); $vias[$connectionindex]->arrival = new ViaDepartureArrival(); $vias[$connectionindex]->arrival->time = $arrivalTime; $vias[$connectionindex]->arrival->platform = new Platform(); $vias[$connectionindex]->arrival->platform->name = $arrivalPlatform; $vias[$connectionindex]->arrival->platform->normal = 1; $vias[$connectionindex]->departure = new ViaDepartureArrival(); $vias[$connectionindex]->departure->time = $departTime; $vias[$connectionindex]->departure->platform = new Platform(); $vias[$connectionindex]->departure->platform->name = $departPlatform; $vias[$connectionindex]->departure->platform->normal = 1; $vias[$connectionindex]->timeBetween = $departTime - $arrivalTime; $vias[$connectionindex]->direction = $directions[$k - 1]; $vias[$connectionindex]->vehicle = "BE.NMBS." . $trains[$j - 1]; $vias[$connectionindex]->station = connections::getStationFromHafasLocation($connsection->Arrival->BasicStop->Station['x'], $connsection->Arrival->BasicStop->Station['y'], $lang); $connectionindex++; } } } if ($connectionindex != 0) { $connection[$i]->via = $vias; } } $connection[$i]->departure->vehicle = "BE.NMBS." . $trains[0]; $connection[$i]->departure->direction = $directions[0]; $connection[$i]->arrival->vehicle = "BE.NMBS." . $trains[sizeof($trains) - 1]; $connection[$i]->arrival->direction = $directions[sizeof($directions) - 1]; $i++; } } else { throw new Exception("We're sorry, we could not retrieve the correct data from our sources", 2); } return $connection; }
/** * @param $locationX * @param $locationY * @param $lang * @return Station */ private static function getStationFromHafasDescription($name, $locationX, $locationY, $lang) { return stations::getStationFromName($name, $lang); }
public static function getStationFromRTName($name, $lang) { APICall::connectToDB(); try { $lang = mysql_real_escape_string(strtoupper($lang)); $name = mysql_real_escape_string($name); $query = "SELECT stations.`ID`,stations.`X`, stations.`Y`, stations.`STD`,stations.`{$lang}` FROM stations RIGHT JOIN railtime ON railtime.`ID` = stations.`ID` WHERE railtime.`RAILTIMENAME` = '{$name}'"; $result = mysql_query($query) or die("Could not get stationslist from DB"); $line = mysql_fetch_array($result, MYSQL_ASSOC); $station = new Station(); $station->id = $line["ID"]; $station->locationX = $line["X"]; $station->locationY = $line["Y"]; if ($line[$lang] != "") { $station->name = $line[$lang]; } else { $station->name = $line["STD"]; } $station->standardname = $line["STD"]; if ($station->id == "") { throw new Exception("doesn't matter what's in here. It doesn't get parsed", 0); } } catch (Exception $e) { //no station found, let's try a HAFAS lookup as last resort return stations::getStationFromName($name, $lang); } return $station; }
/** * @param $html * @param $id * @param $lang * @return null|Vehicle * @throws Exception */ private static function getVehicleData($html, $id, $lang) { // determine the location of the vehicle $test = $html->getElementById('tq_trainroute_content_table_alteAnsicht'); if (!is_object($test)) { throw new Exception('Vehicle not found', 500); } // catch errors $nodes = $html->getElementById('tq_trainroute_content_table_alteAnsicht')->getElementByTagName('table')->children; for ($i = 1; $i < count($nodes); $i++) { $node = $nodes[$i]; if (!count($node->attr)) { continue; } // row with no class-attribute contain no data if (count($node->children[3]->find('a'))) { $as = $node->children[3]->find('a'); $stationname = reset($as[0]->nodes[0]->_); } else { // Foreign station, no anchorlink $stationname = reset($node->children[3]->nodes[0]->_); } $locationX = 0; $locationY = 0; // Station ID can be parsed from the station URL if (isset($node->children[3]->children[0])) { $link = $node->children[3]->children[0]->{'attr'}['href']; // With capital S if (strpos($link, 'StationId=')) { $nr = substr($link, strpos($link, 'StationId=') + strlen('StationId=')); } else { $nr = substr($link, strpos($link, 'stationId=') + strlen('stationId=')); } $nr = substr($nr, 0, strlen($nr) - 1); // delete ampersand on the end $stationId = '00' . $nr; $station = stations::getStationFromID($stationId, $lang); } else { $station = stations::getStationFromName($stationname, $lang); } if (isset($station)) { $locationX = $station->locationX; $locationY = $station->locationY; } $vehicle = new Vehicle(); $vehicle->name = $id; $vehicle->locationX = $locationX; $vehicle->locationY = $locationY; return $vehicle; } return; }
/** * @param $serverData * @param $id * @param $lang * @return null|Vehicle * @throws Exception */ private static function getVehicleData($serverData, $id, $lang) { // determine the location of the vehicle $html = str_get_html($serverData); $test = $html->getElementById('tq_trainroute_content_table_alteAnsicht'); if (!is_object($test)) { throw new Exception("Vehicle not found", 1); } // catch errors $nodes = $html->getElementById('tq_trainroute_content_table_alteAnsicht')->getElementByTagName('table')->children; for ($i = 1; $i < count($nodes); $i++) { $node = $nodes[$i]; if (!count($node->attr)) { continue; } // row with no class-attribute contain no data $as = $node->children[3]->find('a'); $station = reset($as[0]->nodes[0]->_); $locationX = 0; $locationY = 0; if (isset($station)) { $now = stations::getStationFromName($station, $lang); $locationX = $now->locationX; $locationY = $now->locationY; } $vehicle = new Vehicle(); $vehicle->name = $id; $vehicle->locationX = $locationX; $vehicle->locationY = $locationY; return $vehicle; } return null; }
private static function parseData($html, $time, $lang) { $hour = substr($time, 0, 2); preg_match_all("/<tr>(.*?)<\\/tr>/ism", $html, $m); $nodes = array(); $i = 0; //for each row foreach ($m[1] as $tr) { preg_match("/<td valign=\"top\">(.*?)<\\/td><td valign=\"top\">(.*?)<\\/td>/ism", $tr, $m2); //$m2[1] has: time //$m2[2] has delay, stationname & platform //GET LEFT OR NOT $left = 0; if (preg_match("/color=\"DarkGray\"/ism", $tr, $lll) > 0) { $left = 1; } //GET TIME: preg_match("/((\\d\\d):\\d\\d)/", $m2[1], $t); //if it is 23 pm and we fetched data for 1 hour, we may end up with data for the next day and thus we will need to add a day $dayoffset = 0; if ($t[2] != 23 && $hour == 23) { $dayoffset = 1; } $time = "0" . $dayoffset . "d" . $t[1] . ":00"; $dateparam = date("ymd"); //day is previous day if time is before 4 O clock (NMBS-ish thing) if (date('G') < 4) { $dateparam = date("ymd", strtotime("-1 day")); } $unixtime = tools::transformTime($time, "20" . $dateparam); //GET DELAY $delay = 0; preg_match("/\\+(\\d+)'/", $m2[2], $d); if (isset($d[1])) { $delay = $d[1] * 60; } preg_match("/\\+(\\d):(\\d+)/", $m2[2], $d); if (isset($d[1])) { $delay = $d[1] * 3600 + $d[2] * 60; } //GET STATION preg_match("/.* (.*?) <span/", $m2[2], $st); //echo $st[1] . "\n"; $st = explode("/", $st[1]); $st = trim($st[0]); try { $stationNode = stations::getStationFromRTName(strtoupper($st), $lang); } catch (Exception $e) { //fallback: if no railtime name is available, let's ask HAFAS to solve this issue for us $stationNode = stations::getStationFromName($st, $lang); } //GET VEHICLE AND PLATFORM $platform = ""; $platformNormal = true; preg_match("/\\[(.*?)( .*?)?\\]/", $m2[2], $veh); $vehicle = "BE.NMBS." . $veh[1]; if (isset($veh[2])) { if (preg_match("/<[bf].*?>(.*?)<\\/.*?>/", $veh[2], $p)) { $platform = $p[1]; $platformNormal = false; } else { //echo $veh[2] . "\n"; preg_match("/ .*? (.*)/", $veh[2], $p2); if (isset($p2[1])) { $platform = $p2[1]; } } } $nodes[$i] = new DepartureArrival(); $nodes[$i]->delay = $delay; $nodes[$i]->station = $stationNode; $nodes[$i]->time = $unixtime; $nodes[$i]->vehicle = $vehicle; $nodes[$i]->platform = new Platform(); $nodes[$i]->platform->name = $platform; $nodes[$i]->platform->normal = $platformNormal; $nodes[$i]->left = $left; $i++; } return liveboard::removeDuplicates($nodes); }
/** * @param $locationX * @param $locationY * @param $lang * @return Station */ private static function getStationFromHafasDescription($name, $locationX, $locationY, $lang) { preg_match("/(.)(.*)/", $locationX, $m); $locationX = $m[1] . "." . $m[2]; preg_match("/(..)(.*)/", $locationY, $m); $locationY = $m[1] . "." . $m[2]; return stations::getStationFromName($name, $lang); }
/** * @param $xml * @param $time * @param $lang * @param bool $fast * @param bool $showAlerts * @return array */ private static function parseData($xml, $time, $lang, $fast = false, $showAlerts = false) { //clean XML if (class_exists('tidy', false)) { $tidy = new tidy(); $tidy->parseString($xml, ['input-xml' => true, 'output-xml' => true], 'utf8'); $tidy->cleanRepair(); $xml = $tidy; } $data = new SimpleXMLElement($xml); $hour = substr($time, 0, 2); $data = $data->StationTable; //<Journey fpTime="08:36" fpDate="03/09/11" delay="-" //platform="2" targetLoc="Gent-Dampoort [B]" prod="L 758#L" //dir="Eeklo [B]" is_reachable="0" /> $nodes = []; $i = 0; $hour = substr($time, 0, 2); $hour_ = substr((string) $data->Journey[0]['fpTime'], 0, 2); if ($hour_ != '23' && $hour == '23') { $hour_ = 24; } $minutes = substr($time, 3, 2); $minutes_ = substr((string) $data->Journey[0]['fpTime'], 3, 2); while (isset($data->Journey[$i]) && ($hour_ - $hour) * 60 + ($minutes_ - $minutes) <= 60) { $journey = $data->Journey[$i]; $left = 0; $canceled = false; $delay = (string) $journey['delay']; if ($delay == '-') { $delay = '0'; } if ($delay == 'cancel') { $delay = 0; $canceled = true; } if (isset($journey['e_delay'])) { $delay = $journey['e_delay'] * 60; } preg_match("/\\+\\s*(\\d+)/", $delay, $d); if (isset($d[1])) { $delay = $d[1] * 60; } preg_match("/\\+\\s*(\\d):(\\d+)/", $delay, $d); if (isset($d[1])) { $delay = $d[1] * 3600 + $d[2] * 60; } $platform = '?'; // Indicate to end user platform is unknown $platformNormal = true; if (isset($journey['platform'])) { $platform = (string) $journey['platform']; } if (isset($journey['newpl'])) { $platform = (string) $journey['newpl']; $platformNormal = false; } $time = '00d' . (string) $journey['fpTime'] . ':00'; preg_match("/(..)\\/(..)\\/(..)/si", (string) $journey['fpDate'], $dayxplode); $dateparam = '20' . $dayxplode[3] . $dayxplode[2] . $dayxplode[1]; $unixtime = tools::transformtime($time, $dateparam); if ($fast) { $stationNode = new Station(); $stationNode->name = (string) $journey['targetLoc']; $stationNode->name = str_replace(' [B]', '', $stationNode->name); $stationNode->name = str_replace(' [NMBS/SNCB]', '', $stationNode->name); } else { $stationNode = stations::getStationFromName($journey['targetLoc'], $lang); } $veh = $journey['hafasname']; $veh = substr($veh, 0, 8); $veh = str_replace(' ', '', $veh); $vehicle = 'BE.NMBS.' . $veh; $nodes[$i] = new DepartureArrival(); $nodes[$i]->delay = $delay; $nodes[$i]->station = $stationNode; $nodes[$i]->time = $unixtime; $nodes[$i]->vehicle = $vehicle; $nodes[$i]->platform = new Platform(); $nodes[$i]->platform->name = $platform; $nodes[$i]->platform->normal = $platformNormal; $nodes[$i]->canceled = $canceled; $nodes[$i]->left = $left; $hour_ = substr((string) $data->Journey[$i]['fpTime'], 0, 2); if ($hour_ != '23' && $hour == '23') { $hour_ = 24; } $minutes_ = substr((string) $data->Journey[$i]['fpTime'], 3, 2); // Alerts if ($showAlerts && isset($journey->HIMMessage)) { $alerts = []; $himmessage = $journey->HIMMessage; for ($a = 0; $a < count($himmessage); $a++) { $alert = new Alert(); $alert->header = htmlentities(trim($himmessage[$a]['header'])); $alert->description = htmlentities(trim($himmessage[$a]['lead'])); array_push($alerts, $alert); } $nodes[$i]->alert = $alerts; } $i++; } return array_merge($nodes); //array merge reindexes the array }
/** * @param $xml * @param $time * @param $lang * @param bool $fast * @return array */ private static function parseData($xml, $time, $lang, $fast = false) { //clean XML if (class_exists("tidy", false)) { $tidy = new tidy(); $tidy->parseString($xml, ['input-xml' => true, 'output-xml' => true], 'utf8'); $tidy->cleanRepair(); $xml = $tidy; } $data = new SimpleXMLElement($xml); $hour = substr($time, 0, 2); $data = $data->StationTable; //<Journey fpTime="08:36" fpDate="03/09/11" delay="-" //platform="2" targetLoc="Gent-Dampoort [B]" prod="L 758#L" //dir="Eeklo [B]" is_reachable="0" /> $nodes = []; $i = 0; $hour = substr($time, 0, 2); $hour_ = substr((string) $data->Journey[0]["fpTime"], 0, 2); if ($hour_ != "23" && $hour == "23") { $hour_ = 24; } $minutes = substr($time, 3, 2); $minutes_ = substr((string) $data->Journey[0]["fpTime"], 3, 2); while (isset($data->Journey[$i]) && ($hour_ - $hour) * 60 + ($minutes_ - $minutes) <= 60) { $journey = $data->Journey[$i]; $left = 0; $delay = (string) $journey["delay"]; if ($delay == "-") { $delay = "0"; } $platform = ""; if (isset($journey["platform"])) { $platform = (string) $journey["platform"]; } $time = "00d" . (string) $journey["fpTime"] . ":00"; preg_match("/(..)\\/(..)\\/(..)/si", (string) $journey["fpDate"], $dayxplode); $dateparam = "20" . $dayxplode[3] . $dayxplode[2] . $dayxplode[1]; $unixtime = tools::transformtime($time, $dateparam); //GET DELAY preg_match("/\\+\\s*(\\d+)/", $delay, $d); if (isset($d[1])) { $delay = $d[1] * 60; } preg_match("/\\+\\s*(\\d):(\\d+)/", $delay, $d); if (isset($d[1])) { $delay = $d[1] * 3600 + $d[2] * 60; } if ($fast) { $stationNode = new Station(); $stationNode->name = (string) $journey["dir"]; $stationNode->name = str_replace(" [B]", "", $stationNode->name); $stationNode->name = str_replace(" [NMBS/SNCB]", "", $stationNode->name); } else { $stationNode = stations::getStationFromName($journey["dir"], $lang); } //GET VEHICLE AND PLATFORM $platformNormal = true; $veh = $journey["hafasname"]; $veh = substr($veh, 0, 8); $veh = str_replace(" ", "", $veh); $vehicle = "BE.NMBS." . $veh; $nodes[$i] = new DepartureArrival(); $nodes[$i]->delay = $delay; $nodes[$i]->station = $stationNode; $nodes[$i]->time = $unixtime; $nodes[$i]->vehicle = $vehicle; $nodes[$i]->platform = new Platform(); $nodes[$i]->platform->name = $platform; $nodes[$i]->platform->normal = $platformNormal; $nodes[$i]->left = $left; $hour_ = substr((string) $data->Journey[$i]["fpTime"], 0, 2); if ($hour_ != "23" && $hour == "23") { $hour_ = 24; } $minutes_ = substr((string) $data->Journey[$i]["fpTime"], 3, 2); $i++; } return array_merge($nodes); //array merge reindexes the array }
private static function parseData($html, $time, $lang) { $hour = substr($time, 0, 2); preg_match_all("/<table class=\"StationList\">(.*?)<\\/table>/ism", $html, $m); $nodes = array(); $i = 0; //for each row foreach ($m[0] as $table) { $left = 0; preg_match_all("/<tr class=(.*?)>(.*?)<\\/tr>/ism", $table, $m2); if ($m2[1][0] == "rowStation trainLeft") { $left = 1; } preg_match_all("/<label>(.*?)<\\/label>/ism", $m2[2][0], $m3); //$m3[1][0] has : time //$m3[1][1] has : stationname preg_match_all("/<label class=\"orange\">(.*?)<\\/label>/ism", $m2[2][0], $delay); preg_match_all("/<label class=\"bold\">(.*?)<\\/label>/ism", $m2[2][0], $platform); preg_match_all("/<a class=\"button cmd blue\" href=(.*?)>><\\/a>/ism", $m2[2][0], $id); $delay = $delay[1][0]; $platform = $platform[1][0]; $id = $id[1][0]; //GET TIME: preg_match("/((\\d\\d):\\d\\d)/", $m3[1][0], $t); //if it is 23 pm and we fetched data for 1 hour, we may end up with data for the next day and thus we will need to add a day $dayoffset = 0; if ($t[2] != 23 && $hour == 23) { $dayoffset = 1; } $time = "0" . $dayoffset . "d" . $t[1] . ":00"; $dateparam = date("ymd"); //day is previous day if time is before 4 O clock (NMBS-ish thing) if (date('G') < 4) { $dateparam = date("ymd", strtotime("-1 day")); } $unixtime = tools::transformTime($time, "20" . $dateparam); //GET DELAY preg_match("/\\+(\\d+)'/", $delay, $d); if (isset($d[1])) { $delay = $d[1] * 60; } preg_match("/\\+(\\d):(\\d+)/", $delay, $d); if (isset($d[1])) { $delay = $d[1] * 3600 + $d[2] * 60; } //GET STATION $st = trim(utf8_encode($m3[1][1])); try { $stationNode = stations::getStationFromRTName(strtoupper($st), $lang); } catch (Exception $e) { //fallback: if no railtime name is available, let's ask HAFAS to solve this issue for us $stationNode = stations::getStationFromName($st, $lang); } //GET VEHICLE AND PLATFORM $platformNormal = true; $veh = explode(";", $id); $veh = explode("=", $veh[2]); $vehicle = "BE.NMBS." . str_replace("&", "", $veh[1]); $nodes[$i] = new DepartureArrival(); $nodes[$i]->delay = $delay; $nodes[$i]->station = $stationNode; $nodes[$i]->time = $unixtime; $nodes[$i]->vehicle = $vehicle; $nodes[$i]->platform = new Platform(); $nodes[$i]->platform->name = $platform; $nodes[$i]->platform->normal = $platformNormal; $nodes[$i]->left = $left; $i++; } return liveboard::removeDuplicates($nodes); }