muppet77 Posted December 18, 2010 Share Posted December 18, 2010 how could I get the next days forecasted high and low temp from this feed into php variables? feed://view/1292654647//http://newsrss.bbc.co.uk/weather/forecast/2818/Next3DaysRSS.xml any help appreciated. thanks in advance. Link to comment https://forums.phpfreaks.com/topic/222049-extract-weather-data-should-be-simple/ Share on other sites More sharing options...
menator Posted December 18, 2010 Share Posted December 18, 2010 Have a look at SimpleXML Link to comment https://forums.phpfreaks.com/topic/222049-extract-weather-data-should-be-simple/#findComment-1148960 Share on other sites More sharing options...
muppet77 Posted December 18, 2010 Author Share Posted December 18, 2010 thanks. are there any easy to follow examples anywhere? Link to comment https://forums.phpfreaks.com/topic/222049-extract-weather-data-should-be-simple/#findComment-1148971 Share on other sites More sharing options...
harristweed Posted December 18, 2010 Share Posted December 18, 2010 <?php $xml_feed="http://feeds.bbc.co.uk/weather/forecast/2818/Next3DaysRSS.xml"; if($xml = simplexml_load_file("$xml_feed")); foreach ($xml->channel->item as $value) { $title=$value->title; $title=utf8_decode($title); $title=str_replace(",","<br />",$title); echo "<p>$title</p>"; } ?> Link to comment https://forums.phpfreaks.com/topic/222049-extract-weather-data-should-be-simple/#findComment-1148976 Share on other sites More sharing options...
muppet77 Posted December 18, 2010 Author Share Posted December 18, 2010 great! is there a way to separate out the text - i would just like the next day's forecasted high and low in degrees C? ie the -1 and -6 for SUNDAY (it is saturday now) can i store these two values as variables? Link to comment https://forums.phpfreaks.com/topic/222049-extract-weather-data-should-be-simple/#findComment-1148985 Share on other sites More sharing options...
muppet77 Posted December 19, 2010 Author Share Posted December 19, 2010 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 https://forums.phpfreaks.com/topic/222049-extract-weather-data-should-be-simple/#findComment-1149182 Share on other sites More sharing options...
menator Posted December 19, 2010 Share Posted December 19, 2010 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 https://forums.phpfreaks.com/topic/222049-extract-weather-data-should-be-simple/#findComment-1149193 Share on other sites More sharing options...
muppet77 Posted December 19, 2010 Author Share Posted December 19, 2010 thanks, that now produces: Max Temp: -1°C (30°F) Min Temp: -8°C (18°F) i really just want the -1 as a variable and also the -8. ...and then the next day aswell..? i am a real beginner to all this. they are arrays right? Link to comment https://forums.phpfreaks.com/topic/222049-extract-weather-data-should-be-simple/#findComment-1149197 Share on other sites More sharing options...
muppet77 Posted December 19, 2010 Author Share Posted December 19, 2010 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 https://forums.phpfreaks.com/topic/222049-extract-weather-data-should-be-simple/#findComment-1149206 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.