RE: Syntax for cvs-phpweather???
Brought to you by:
iridium
From: Max H. <ma...@fl...> - 2002-03-29 01:05:02
|
> $weather = new phpweather(array()); $weather->set_metar('KVCT'); First up, you need to call set_icao('KVCT'); rather than set_metar() [you can use set_metar() to feed it a metar directly for testing] > $text->print_pretty(); > $icons = new pw_images($weather, array()); you don't need to include pw_images or instantiate this class unless you want do display some pretty icons. Now, to get the values out of the metar. I've just comitted a function to CVS that will let you do this - update your code if you're using cvs, or wait for the next tarball if you're not. The easiest way to see how to use it is as follows: First, you need to see the structure that a metar is stored in - just while you're working out what to do next. so echo '<pre>'; print_r($weather->decode_metar()); echo '</pre>'; Next, you need to choose the information you want out. for temperature, you need $metar['temperature']['temp_f'] You can see this in the output from the first bit, where you have [temperature] => Array ( [temp_c] => 25 [temp_f] => 77 [dew_c] => 19 [dew_f] => 66 ) That's telling you that within the array which is storing the metar, there is an array storing the temp, which has an index temp_f with what you need in in. How to get at it: echo $text->get_metar_value('temperature','temp_f'); that function will take up to three arguments, which will drill into arrays stored within the metar. So to get the relative humidity, echo $text->get_metar_value('rel_humidity'); - only one argument because it's not an array of it's own, it's just a value. This is all a bit of a hack, there's something not terribly appealing about having to drill through arrays to find the value you need. I'll see if I have any cunning ideas about how to make it more accessible for extension. Max |