Overview
To use PHPWeatherLib, you must do three things:
- Include the PHP file phpweatherlib.php in your PHP page
on your PHP enabled web server or hosting plan.
- Create a WeatherLib object with the NOAA reporting station
call letters as the only argument.
- Call any of the PHPWeatherLib functions to return current
weather data from the reporting station specified.
Including the PHP file
To include the PHP file, add this php include call at the top
of your page source code:
Creating the WeatherLib Object
Before you create the Weather Lib Object you must find the
call letters to the NOAA weather reporting station that you
wish to reference. Visit the NOAA's National Weather Service
page to find the appropriate weather station. http://www.weather.gov/data/current_obs/
Click the Select a State drop down and then click Find. A list
of results for that state will be shown followed by four uppercase
call letters (example KJFK, KJAN, etc.)
Now you can create the WeatherLib object in your source code.
Create an object by assigning a variable to a new instance of
the WeatherLib object with the call letters as the only argument
to the object constructor. For example, to create the object
for New York's JFK Airport, call letters KJFK, use the following
PHP code:
WeatherLib includes error reporting and supporting functions.
To handle errors gracefully, it is recommended that your use
these feature when creating a WeatherLib() object.
The following code displays the appropriate error message if
the WeatherLib object cannot be created or has trouble parsing
the XML weather feed.
Calling
PHPWeatherLib's Functions to Return Weather Data
There are many included functions in the PHPWeatherLib library
to retrieve weather data from the station you specified when
creating the WeatherLib() object. Below is an example of a few
of these functions. The full function list is listed below in
the Function Reference section.
The following code displays:
Right now in New York City, Central Park, NY it is 39.0 F!
|