Re: PHP Weather 2.1.2
Brought to you by:
iridium
|
From: Martin G. <gim...@gi...> - 2003-05-12 22:38:29
|
Dan Martin <da...@da...> writes:
> I have figured out after struggling a bit how to pull most of the
> information in 2.1.2, but I am still having difficulties pulling
> "Clouds" and "Weather." I know that the information is in an array,
> but I am unclear on how to bring it out of the array.
>
> I also cannot seem to pull wind direction (SW, NW, W), but I can
> pull the compass degree (135, 90, 110).
>
>
> Here is the code:
>
>
> $weather = new phpweather();
> $icons = new pw_images($weather);
> $location = $weather->get_location();
> $image = $icons->get_sky_image();
> $data = $weather->decode_metar();
> $temp = $data[temperature];
> $windvar = $data[wind]; <-----This Doesn't Work
> $cloudvar = $data[clouds]; <-----This Doesn't Work
> $time = date("m/d/y g:i a",($data[time]));
> $weathervar = $data[weather];
First of all, please remember to use strings when you index into an
array. Like this: $var = $some_array['some index']. The other way is
deprecated...
To see the structure of the array do this:
echo "<pre>\n";
print_r($data);
echo "</pre>\n";
Then you'll see that $data['wind'] is yet another array that contains
up to eight entries depending on the weather. You'll always find these
entries:
$data['wind']['deg']; // Wind direction in degrees
$data['wind']['knots']; // Wind speed, knots.
$data['wind']['miles_per_hour']; // Wind speed, miles per hour.
$data['wind']['meters_per_second']; // Wind speed, m/s.
If there are gusts, then you'll find these entries as well:
$data['wind']['gust_knots']
$data['wind']['gust_meters_per_second']
$data['wind']['gust_miles_per_hour']
Finally, the wind might be varying between two directions:
$data['wind']['var_beg']
$data['wind']['var_end']
As for the $data['clouds'] entry, then this is an array of arrays. The
first entry is the first cloud-layer, the second entry is the layer
above etc. So
$data['clouds'][0]['condition']
could be FEW if there were few clouds in the first layer. The altitude
of this layer is
$data['clouds'][0]['metar'] or
$data['clouds'][0]['ft'].
The second layer (if there is such a layer) is stored at
$data['clouds'][1].
You'll notice that the data in $data is language-neutral. You'll have
to provide your own strings for N, NW, W etc when you parse the
data. The best way would probably be to make a new method in
pw_text.php and then reuse the strings and other methods that are
already present there.
If you come up with a good extenstion of pw_text.php, then please send
it to the list so that it can become part of the distribution.
--
Martin Geisler My GnuPG Key: 0xF7F6B57B
See http://gimpster.com/ and http://phpweather.net/ for:
PHP Weather: Shows the current weather on your webpage and
PHP Shell: A telnet-connection (almost :-) in a PHP page.
Join Freenet: http://gimpster.com/downloads/freenet/
|