当前位置: 首页>>代码示例>>PHP>>正文


PHP tools::transformTime方法代码示例

本文整理汇总了PHP中tools::transformTime方法的典型用法代码示例。如果您正苦于以下问题:PHP tools::transformTime方法的具体用法?PHP tools::transformTime怎么用?PHP tools::transformTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tools的用法示例。


在下文中一共展示了tools::transformTime方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getData

     private static function getData($serverData, $lang){
	  try{
               $stops = array();
               $html = str_get_html($serverData);
               $nodes = $html->find("tr.rowHeightTraject");
               $i = 0;
               foreach ($nodes as $node) {
                    $row_delay = str_replace("'",'',str_replace('+','',trim($node->children(3)->first_child()->plaintext)));
                    if (isset($row_delay)) {
                         $arr= array();
                         $arr = explode(":",$row_delay);
                         if(isset($arr[1])){
                              $delay = (60*$arr[0] + $arr[1])*60;
                         }else{
                              $delay = $row_delay * 60;
                         }
                    } else {
                         $delay = 0;
                    }
                    $stops[$i] = new Stop();
                    $stops[$i]->station = stations::getStationFromRTName($node->children(1)->first_child()->plaintext,$lang);
                    $stops[$i]->delay = $delay;
                    $stops[$i]->time = tools::transformTime("00d" . $node->children(2)->first_child()->plaintext . ":00", date("Ymd"));
                    $i++;
               }
	       return $stops;
	  }
	  catch(Exception $e){
	       throw new Exception($e->getMessage(), 500);
	  }
     }
开发者ID:GMLudo,项目名称:iRail,代码行数:31,代码来源:vehicleinformation.php

示例2: getData

     private static function getData($serverData, $lang){
	  try{
	       $stops = array();
	       //BEGIN: O 20:29 +8'&nbsp;<a.*? >(.*?)</a><br>
	       //NORMAL: | 20:50 +9'&nbsp;<a href="/mobile/SearchStation.aspx?l=NL&s=1&sid=1265&tr=20:45-60&da=D&p=2">Zele</a><br>
	       //AT: =&gt;22:01&nbsp;<a href="/mobile/SearchStation.aspx?l=NL&s=1&sid=318&tr=22:00-60&da=D&p=2">Denderleeuw</a></font><br>
	       //BETWEEN: <font face="Arial">| 10:35</font><font color="Red"> +15'</font><font face="Arial">&nbsp;<a href="/mobile/SearchStation.aspx?l=NL&s=1&sid=215&tr=10:45-60&da=D&p=2">Brussel-Centraal</a><br>
	       //        | 10:40<font color="Red"> +15'</font></font>&nbsp;<a href="/mobile/SearchStation.aspx?l=NL&s=1&sid=221&tr=10:45-60&da=D&p=2">Brussel-Noord</a><br>
	       //END: O 23:28&nbsp;<a href="/mobile/SearchStation.aspx?l=NL&s=1&sid=973&tr=23:15-60&da=D&p=2">Poperinge</a><br>
	       preg_match_all("/(\d\d:\d\d).*?( \+(\d\d?(:?\d\d)?)'?)?&nbsp;<a href=\"\/mobile\/SearchStation.*?>(.*?)<\/a>/smi", $serverData, $matches);
	       $delays = $matches[3];
	       $times = $matches[0];
	       $stationnames = $matches[5];
	       $i = 0;
	       foreach ($stationnames as $st) {
		    if (isset($delays[$i])) {
			 $arr= array();
			 $arr = explode(":",$delays[$i]);
			 if(isset($arr[1])){
			      $delay = (60*$arr[0] + $arr[1])*60;
			 }else{
			      $delay = $delays[$i] * 60;
			 }
		    } else {
			 $delay = 0;
		    }
		    $time = tools::transformTime("00d" . $times[$i] . ":00", date("Ymd"));
		    $stops[$i] = new Stop();
		    $stops[$i]->station = stations::getStationFromRTName($st,$lang);
		    $stops[$i]->delay = $delay;
		    $stops[$i]->time = $time;
		    $i++;
	       }
	       return $stops;
	  }
	  catch(Exception $e){
	       throw new Exception($e->getMessage(), 500);
	  }
     }
开发者ID:JeroenDeDauw,项目名称:iRail,代码行数:39,代码来源:vehicleinformation.php

示例3: parseHafasXml

 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++;
//.........这里部分代码省略.........
开发者ID:JeroenDeDauw,项目名称:iRail,代码行数:101,代码来源:connections.php

示例4: parseHafasXml

 public static function parseHafasXml($serverData, $lang, $fast, $showAlerts = false)
 {
     $xml = new SimpleXMLElement($serverData);
     $connection = [];
     $i = 0;
     if (isset($xml->ConRes->ConnectionList->Connection)) {
         $fromstation = self::getStationFromHafasDescription($xml->ConRes->ConnectionList->Connection[0]->Overview->Departure->BasicStop->Station['name'], $xml->ConRes->ConnectionList->Connection[0]->Overview->Departure->BasicStop->Station['x'], $xml->ConRes->ConnectionList->Connection[0]->Overview->Departure->BasicStop->Station['y'], $lang);
         $tostation = self::getStationFromHafasDescription($xml->ConRes->ConnectionList->Connection[0]->Overview->Arrival->BasicStop->Station['name'], $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]->duration = tools::transformDuration($conn->Overview->Duration->Time);
             $connection[$i]->departure = new DepartureArrival();
             $connection[$i]->departure->station = $fromstation;
             $connection[$i]->departure->direction = trim($conn->Overview->Departure->BasicStop->Dep->Platform->Text);
             $connection[$i]->departure->time = tools::transformTime($conn->Overview->Departure->BasicStop->Dep->Time, $conn->Overview->Date);
             $connection[$i]->departure->canceled = $conn->Overview->Departure->BasicStop->StopPrognosis->Status != "SCHEDULED" ? true : false;
             $connection[$i]->arrival = new DepartureArrival();
             $connection[$i]->arrival->station = $tostation;
             $connection[$i]->arrival->time = tools::transformTime($conn->Overview->Arrival->BasicStop->Arr->Time, $conn->Overview->Date);
             $connection[$i]->arrival->canceled = $conn->Overview->Arrival->BasicStop->StopPrognosis->Status != "SCHEDULED" ? true : false;
             //Delay and platform changes
             $departureDelay = 0;
             $departurePlatform = trim($conn->Overview->Departure->BasicStop->Dep->Platform->Text);
             $departurePlatformNormal = true;
             $arrivalDelay = 0;
             $arrivalPlatform = trim($conn->Overview->Arrival->BasicStop->Arr->Platform->Text);
             $arrivalPlatformNormal = true;
             if ($conn->RtStateList->RtState['value'] == 'HAS_DELAYINFO') {
                 //echo "delay: " .$conn->Overview -> Departure -> BasicStop -> StopPrognosis -> Dep -> Time . "\n";
                 $departureDelay = tools::transformTime($conn->Overview->Departure->BasicStop->StopPrognosis->Dep->Time, $conn->Overview->Date) - $connection[$i]->departure->time;
                 if ($departureDelay < 0) {
                     $departureDelay = 0;
                 }
                 $arrivalDelay = tools::transformTime($conn->Overview->Arrival->BasicStop->StopPrognosis->Arr->Time, $conn->Overview->Date) - $connection[$i]->arrival->time;
                 if ($arrivalDelay < 0) {
                     $arrivalDelay = 0;
                 }
                 if (isset($conn->Overview->Departure->BasicStop->StopPrognosis->Dep->Platform->Text)) {
                     $departurePlatform = trim($conn->Overview->Departure->BasicStop->StopPrognosis->Dep->Platform->Text);
                     $departurePlatformNormal = false;
                 }
                 if (isset($conn->Overview->Arrival->BasicStop->StopPrognosis->Arr->Platform->Text)) {
                     $arrivalPlatform = trim($conn->Overview->Arrival->BasicStop->StopPrognosis->Arr->Platform->Text);
                     $arrivalPlatformNormal = false;
                 }
             }
             // Alerts
             if ($showAlerts && isset($conn->IList)) {
                 $alerts = [];
                 foreach ($conn->IList->I as $info) {
                     $alert = new Alert();
                     $alert->header = htmlentities(trim($info['header']));
                     $alert->description = htmlentities(trim($info['text']));
                     array_push($alerts, $alert);
                 }
                 $connection[$i]->alert = $alerts;
             }
             $connection[$i]->departure->delay = $departureDelay;
             $connection[$i]->departure->platform = new Platform();
             $connection[$i]->departure->platform->name = $departurePlatform;
             $connection[$i]->departure->platform->normal = $departurePlatformNormal;
             $connection[$i]->arrival->delay = $arrivalDelay;
             $connection[$i]->arrival->platform = new Platform();
             $connection[$i]->arrival->platform->name = $arrivalPlatform;
             $connection[$i]->arrival->platform->normal = $arrivalPlatformNormal;
             $trains = [];
             $vias = [];
             $directions = [];
             $j = 0;
             $k = 0;
             $connectionindex = 0;
             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++;
                             } elseif ($att->Attribute['type'] == 'DIRECTION') {
                                 $__stat = new stdClass();
                                 //This recently changed: only fetch direction name, nothing else.
                                 $__stat->name = str_replace(' [NMBS/SNCB]', '', trim($att->Attribute->AttributeVariant->Text));
                                 $directions[$k] = $__stat;
                                 $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
                             $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);
                             $departDelay = 0;
                             //Todo: NYImplemented
                             $departcanceled = $connarray[$connectionindex + 1]->Departure->BasicStop->StopPrognosis->Status != "SCHEDULED" ? true : false;
                             $arrivalTime = tools::transformTime($connsection->Arrival->BasicStop->Arr->Time, $conn->Overview->Date);
                             $arrivalPlatform = trim($connsection->Arrival->BasicStop->Arr->Platform->Text);
                             $arrivalDelay = 0;
                             //Todo: NYImplemented
                             $arrivalcanceled = $connarray[$connectionindex + 1]->Arrival->BasicStop->StopPrognosis->Status != "SCHEDULED" ? true : false;
                             $vias[$connectionindex] = new Via();
//.........这里部分代码省略.........
开发者ID:jncn,项目名称:iRail,代码行数:101,代码来源:connections.php

示例5: getData

 /**
  * @param $html
  * @param $lang
  * @param $fast
  * @return array
  * @throws Exception
  */
 private static function getData($html, $lang, $fast)
 {
     try {
         $stops = [];
         $nodes = $html->getElementById('tq_trainroute_content_table_alteAnsicht')->getElementByTagName('table')->children;
         $j = 0;
         for ($i = 1; $i < count($nodes); $i++) {
             $node = $nodes[$i];
             if (!count($node->attr)) {
                 continue;
             }
             // row with no class-attribute contain no data
             // Delay and canceled
             $splitter = '***';
             $delaycontent = preg_replace("/<br\\W*?\\/>/", $splitter, $node->children[2]);
             $delayelements = explode($splitter, strip_tags($delaycontent));
             // print_r($delayelements);
             $arrivalDelay = trim($delayelements[0]);
             $arrivalCanceled = false;
             if (!$arrivalDelay) {
                 $arrivalDelay = 0;
             } elseif (stripos($arrivalDelay, '+') !== false) {
                 $arrivalDelay = preg_replace('/[^0-9]/', '', $arrivalDelay) * 60;
             } else {
                 $arrivalDelay = 0;
                 $arrivalCanceled = true;
             }
             $departureDelay = trim($delayelements[1]);
             $departureCanceled = false;
             if (!$departureDelay) {
                 $departureDelay = $arrivalDelay ? $arrivalDelay : 0;
             } elseif (stripos($departureDelay, '+') !== false) {
                 $departureDelay = preg_replace('/[^0-9]/', '', $departureDelay) * 60;
             } else {
                 $departureDelay = 0;
                 $departureCanceled = true;
             }
             // Time
             $timenodearray = $node->children[1]->find('span');
             $arriveTime = reset($timenodearray[0]->nodes[0]->_);
             $departureTime = count($nodes[$i]->children[1]->children) == 3 ? reset($nodes[$i]->children[1]->children[2]->nodes[0]->_) : $arriveTime;
             if (count($node->children[3]->find('a'))) {
                 $as = $node->children[3]->find('a');
                 $stationname = reset($as[0]->nodes[0]->_);
             } else {
                 $stationname = reset($node->children[3]->nodes[0]->_);
             }
             // Platform
             $platformnodearray = $node->children[5]->find('span');
             if (count($platformnodearray) > 0) {
                 $normalplatform = 0;
                 $platform = trim(reset($platformnodearray[0]->nodes[0]->_));
             } else {
                 $normalplatform = 1;
                 $platform = trim(reset($node->children[5]->nodes[0]->_));
             }
             if ($platform == "&nbsp;") {
                 $platform = '?';
                 // Indicate to end user platform is unknown
             }
             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 = new Station();
             if ($fast == 'true') {
                 $station->name = $stationname;
                 if ($stationId) {
                     $station->id = "BE.NMBS." . $stationId;
                 }
             } else {
                 // Station ID can be parsed from the station URL
                 if ($stationId) {
                     $station = stations::getStationFromID($stationId, $lang);
                 } else {
                     $station = stations::getStationFromName($stationname, $lang);
                 }
             }
             $stops[$j] = new Stop();
             $stops[$j]->station = $station;
             $stops[$j]->delay = $departureDelay;
             $stops[$j]->canceled = $departureCanceled;
             $stops[$j]->time = tools::transformTime('00d' . $departureTime . ':00', date('Ymd'));
             $stops[$j]->platform = new Platform();
             $stops[$j]->platform->name = $platform;
//.........这里部分代码省略.........
开发者ID:jncn,项目名称:iRail,代码行数:101,代码来源:vehicleinformation.php

示例6: getData

 /**
  * @param $serverData
  * @param $lang
  * @param $fast
  * @return array
  * @throws Exception
  */
 private static function getData($serverData, $lang, $fast)
 {
     try {
         $stops = [];
         $html = str_get_html($serverData);
         $nodes = $html->getElementById('tq_trainroute_content_table_alteAnsicht')->getElementByTagName('table')->children;
         $j = 0;
         for ($i = 1; $i < count($nodes); $i++) {
             $node = $nodes[$i];
             if (!count($node->attr)) {
                 continue;
             }
             // row with no class-attribute contain no data
             $delaynodearray = $node->children[2]->find('span');
             $delay = count($delaynodearray) > 0 ? trim(reset($delaynodearray[0]->nodes[0]->_)) : "0";
             $delayseconds = preg_replace("/[^0-9]/", '', $delay) * 60;
             $spans = $node->children[1]->find('span');
             $arriveTime = reset($spans[0]->nodes[0]->_);
             $departureTime = count($nodes[$i]->children[1]->children) == 3 ? reset($nodes[$i]->children[1]->children[0]->nodes[0]->_) : $arriveTime;
             if (count($node->children[3]->find('a'))) {
                 $as = $node->children[3]->find('a');
                 $stationname = reset($as[0]->nodes[0]->_);
             } else {
                 $stationname = reset($node->children[3]->nodes[0]->_);
             }
             $stops[$j] = new Stop();
             $station = new Station();
             if ($fast == "true") {
                 $station->name = $stationname;
             } else {
                 $station = stations::getStationFromName($stationname, $lang);
             }
             $stops[$j]->station = $station;
             $stops[$j]->delay = $delayseconds;
             $stops[$j]->time = tools::transformTime("00d" . $departureTime . ":00", date("Ymd"));
             $j++;
         }
         return $stops;
     } catch (Exception $e) {
         throw new Exception($e->getMessage(), 500);
     }
 }
开发者ID:Tjoosten,项目名称:iRail,代码行数:49,代码来源:vehicleinformation.php

示例7: parseData

 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("/.*&nbsp;(.*?)&nbsp;<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("/\\[(.*?)(&nbsp;.*?)?\\]/", $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("/&nbsp;.*?&nbsp;(.*)/", $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);
 }
开发者ID:JeroenDeDauw,项目名称:iRail,代码行数:81,代码来源:liveboard.php

示例8: parseHafasXml

 public static function parseHafasXml($serverData, $lang, $fast)
 {
     $xml = new SimpleXMLElement($serverData);
     $connection = [];
     $i = 0;
     //DEBUG:
     //echo $serverData ;
     if (isset($xml->ConRes->ConnectionList->Connection)) {
         //get stations from & to once for all connections
         $fromstation = connections::getStationFromHafasDescription($xml->ConRes->ConnectionList->Connection[0]->Overview->Departure->BasicStop->Station['name'], $xml->ConRes->ConnectionList->Connection[0]->Overview->Departure->BasicStop->Station['x'], $xml->ConRes->ConnectionList->Connection[0]->Overview->Departure->BasicStop->Station['y'], $lang);
         $tostation = connections::getStationFromHafasDescription($xml->ConRes->ConnectionList->Connection[0]->Overview->Arrival->BasicStop->Station['name'], $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 = [];
             $vias = [];
             $directions = [];
             $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++;
                             } elseif ($att->Attribute["type"] == "DIRECTION") {
                                 $__stat = new stdClass();
                                 //This recently changed: only fetch direction name, nothing else.
                                 $__stat->name = str_replace(" [NMBS/SNCB]", "", trim($att->Attribute->AttributeVariant->Text));
                                 $directions[$k] = $__stat;
                                 $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;
                             if (isset($directions[$k - 1])) {
                                 $vias[$connectionindex]->direction = $directions[$k - 1];
//.........这里部分代码省略.........
开发者ID:Tjoosten,项目名称:iRail,代码行数:101,代码来源:connections.php

示例9: parseData

 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=(.*?)>&gt;<\\/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("&amp", "", $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);
 }
开发者ID:GMLudo,项目名称:iRail,代码行数:71,代码来源:liveboard.php


注:本文中的tools::transformTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。