Jump to content

extract weather data. should be simple.


muppet77

Recommended Posts

ok i now have this as code:

 

<?php 

// set name of XML file 
$file = "http://feeds.bbc.co.uk/weather/forecast/2818/Next3DaysRSS.xml"; 

// load file 
$xml = simplexml_load_file($file) or die ("Unable to load XML file!"); 


foreach ($xml->channel->item as $value) {
$title=$value->title;
$title=utf8_decode($title);
$title=str_replace(",","<br />",$title);
$length = strpos($title, "Min Temp:") - strpos($title, "Max Temp:") - 26; 
echo substr($title,strpos($title, "Max Temp:")+10,$length);
}
?> 

 

which gives

 

-3-11

 

how can i name them 3 separate variables?

 

i am soo close..

Link to comment
Share on other sites

Here is something for you to work with.

<?php
$file = "http://feeds.bbc.co.uk/weather/forecast/2818/Next3DaysRSS.xml"; 
$xml = simplexml_load_file($file);


$temps_array = $xml->xpath('channel/item/description');
$temp = explode(',',$temps_array[0]);

echo $temp[0] . '<br />' . $temp[1];
?>

Link to comment
Share on other sites

got there. works a treat. i only wanted tomorrow's max and min.

 

<?php
$file = "http://feeds.bbc.co.uk/weather/forecast/2818/Next3DaysRSS.xml"; 
$xml = simplexml_load_file($file);
$temps_array = $xml->xpath('channel/item/description');
$temp2 = explode(',',$temps_array[1]);
$max = substr(trim($temp2[0]),10,strlen(trim($temp2[0]))-21);
$min = substr(trim($temp2[1]),10,strlen(trim($temp2[1]))-21);
echo $max;
echo $min;
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.