Skip to content

Instantly share code, notes, and snippets.

@ronnyandre
Created February 22, 2011 21:42
Show Gist options
  • Save ronnyandre/839475 to your computer and use it in GitHub Desktop.
Save ronnyandre/839475 to your computer and use it in GitHub Desktop.
<?php
// URL til varselet
$url = 'http://www.yr.no/sted/Norge/Hordaland/Bergen/Bergen/varsel.xml';
// Les data fra URL
$xmldata = file_get_contents($url);
// Les dataene og gjør om til SimpleXML-objekt
$xml = new SimpleXMLElement($xmldata);
/*
* Eksempel 1
* Les ut temperaturer for det neste døgnet
*/
for ($i = 0; $i <= 3; $i++) {
echo 'Temperatur fra '.$xml->forecast->tabular->time[$i]['from'].' til '.$xml->forecast->tabular->time[$i]['to'].': ';
echo $xml->forecast->tabular->time[$i]->temperature['value'].'<br />';
}
/*
* Eksempel 2
* Les ut temperaturen i inneværende periode
*/
echo 'Snart er temperaturen '.$xml->forecast->tabular->time[0]->temperature['value'].'&deg;C';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment