Created
February 22, 2011 21:42
-
-
Save ronnyandre/839475 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'].'°C'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment