XML is outputting time like this:
<time from="2020-02-03T12:00:00" to="2020-02-03T18:00:00" period="2"
^ this is dynamic and changes all the time ^
I would want to display it like this:
- Feb 12:00 - 18:00
This is my PHP:
$url = ('https://www.yr.no/sted/Norge/Oslo/Oslo/Oslo/varsel.xml');
$feed = simplexml_load_file($url) or die('Can not connect to server');
$result = array();
foreach ($feed->forecast->tabular->time as $content) {
array_push($result, [ "from" => (string)$content['from'],
"to" => (string)$content['to'],
'symbol' => (string)$content->symbol['name'],
'temperature' => (string)$content->temperature['value'],
'windDirection' => (string)$content->windDirection['code'],
'windSpeed' => (string)$content->windSpeed['mps'],
]);
}
This is my html:
<section>
<div class="tbl-header">
<table cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th>Time</th>
<th>Weather</th>
<th>Temperature</th>
<th>Wind</th>
</tr>
</thead>
</table>
</div>
<div class="tbl-content">
<table cellpadding="0" cellspacing="0" border="0">
<tbody>
<?php foreach ($result as $value) { ?>
<tr>
<td>Bergen <br /><?php echo $value['from'] ?> til <?php echo $value['to'] ?></td>
<td><?php echo $value['symbol'] ?></td>
<td><?php echo $value['temperature'] ?> °C</td>
<td><?php echo $value['windSpeed'] ?> m/s fra <?php echo $value['windDirection'] ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</section>
how can I do that the best way by using php? Any help is greatly appreciated.