example.php
Gesponsorde koppelingen
PHP script bestanden
Code (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
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
<?php
require 'ns.class.php';
try
{
$oNS = new NSAPI('-- api key --');
$aTrips = $oNS->getTrips('Groningen', 'Amsterdam centraal', 'Utrecht centraal', date('d-m-Y H:i:s'));
if(!empty($aTrips))
{
foreach($aTrips as $oTrip)
{
if(isset($oTrip->legs) && !empty($oTrip->legs))
{
$oStartLeg = $oTrip->legs[0];
$oEndLeg = $oTrip->legs[count($oTrip->legs)-1];
echo '<h4>'. $oStartLeg->origin->name .' - '. $oEndLeg->destination->name .'</h4>';
echo 'Vertrek: '. date('d-m-Y H:i', strtotime($oStartLeg->origin->actualDateTime ?? $oStartLeg->origin->plannedDateTime)) .'<br/>';
echo 'Aankomst: '. date('d-m-Y H:i', strtotime($oEndLeg->destination->actualDateTime ?? $oEndLeg->destination->plannedDateTime)) .'<br/>';
echo '<hr><ul>';
foreach($oTrip->legs as $oLeg)
{
$iDuration = (strtotime($oLeg->destination->actualDateTime ?? $oLeg->destination->plannedDateTime) - strtotime($oLeg->origin->actualDateTime ?? $oLeg->origin->plannedDateTime)) / 60;
echo '<li>'.
date('H:i', strtotime($oLeg->origin->actualDateTime ?? $oLeg->origin->plannedDateTime)) .' - '.
date('H:i', strtotime($oLeg->destination->actualDateTime ?? $oLeg->destination->plannedDateTime)) .' '.
$oLeg->origin->name .' - '. $oLeg->destination->name .' ('. $iDuration .' minuten)
</li>';
}
echo '</ul>';
}
echo '<hr>';
}
}
}
catch(Exception $e)
{
echo 'Error: '. $e->getMessage();
}
?>
require 'ns.class.php';
try
{
$oNS = new NSAPI('-- api key --');
$aTrips = $oNS->getTrips('Groningen', 'Amsterdam centraal', 'Utrecht centraal', date('d-m-Y H:i:s'));
if(!empty($aTrips))
{
foreach($aTrips as $oTrip)
{
if(isset($oTrip->legs) && !empty($oTrip->legs))
{
$oStartLeg = $oTrip->legs[0];
$oEndLeg = $oTrip->legs[count($oTrip->legs)-1];
echo '<h4>'. $oStartLeg->origin->name .' - '. $oEndLeg->destination->name .'</h4>';
echo 'Vertrek: '. date('d-m-Y H:i', strtotime($oStartLeg->origin->actualDateTime ?? $oStartLeg->origin->plannedDateTime)) .'<br/>';
echo 'Aankomst: '. date('d-m-Y H:i', strtotime($oEndLeg->destination->actualDateTime ?? $oEndLeg->destination->plannedDateTime)) .'<br/>';
echo '<hr><ul>';
foreach($oTrip->legs as $oLeg)
{
$iDuration = (strtotime($oLeg->destination->actualDateTime ?? $oLeg->destination->plannedDateTime) - strtotime($oLeg->origin->actualDateTime ?? $oLeg->origin->plannedDateTime)) / 60;
echo '<li>'.
date('H:i', strtotime($oLeg->origin->actualDateTime ?? $oLeg->origin->plannedDateTime)) .' - '.
date('H:i', strtotime($oLeg->destination->actualDateTime ?? $oLeg->destination->plannedDateTime)) .' '.
$oLeg->origin->name .' - '. $oLeg->destination->name .' ('. $iDuration .' minuten)
</li>';
}
echo '</ul>';
}
echo '<hr>';
}
}
}
catch(Exception $e)
{
echo 'Error: '. $e->getMessage();
}
?>