Thread: Re: PHP Weather 2.1.2
Brought to you by:
iridium
From: Dan M. <da...@da...> - 2003-05-12 16:58:14
|
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]; echo "\n"; echo "<div align='center'> Portland, Oregon<br /> <img src=\"$image\" height='45' width='75' border='0' alt='Current Sky' />"; echo "<br />$weathervar[condition]<br /> </div>"; echo "<b>Temperature:</b> $temp[temp_f]°F<br />"; echo "<b>Humidity:</b> $data[rel_humidity]%<br />"; echo "<b>Wind:</b> $windvar[miles_per_hour]mph<br /> <div align='center'>$time</div> "; Thank you, Dan Martin |
From: Pedro L. <li...@le...> - 2003-05-12 17:12:51
|
Hey Dan, On Mon, May 12, 2003 at 09:54:00AM -0700, Dan Martin wrote: > 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 had a problem where the METAR info that is pulled from the site and imported into the database went stale and wouldn't refresh. Anyone have the same issue? Maybe I didn't configure it right, but I do remember setting a timeout or expiration time. > > I also cannot seem to pull wind direction (SW, NW, W), but I can pull > the compass degree (135, 90, 110). I had this same issue when I was playing with 2.1.2. What I actually printed all the values in the array and see what info I could sort out and pull, but I couldn't find wind info. I'm going to play with 2.1.2 now and see what I can do with it. -Pedro > > > 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]; > > > echo "\n"; > echo "<div align='center'> > Portland, Oregon<br /> > <img src=\"$image\" height='45' width='75' border='0' alt='Current Sky' />"; > > > echo "<br />$weathervar[condition]<br /> > > </div>"; > > echo "<b>Temperature:</b> $temp[temp_f]°F<br />"; > echo "<b>Humidity:</b> $data[rel_humidity]%<br />"; > echo "<b>Wind:</b> $windvar[miles_per_hour]mph<br /> > <div align='center'>$time</div> > "; > > Thank you, > Dan Martin > > > > ------------------------------------------------------- > Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara > The only event dedicated to issues related to Linux enterprise solutions > www.enterpriselinuxforum.com > > _______________________________________________ > PHPWeather-devel mailing list > PHP...@li... > https://lists.sourceforge.net/lists/listinfo/phpweather-devel |
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/ |