PHP Classes

WeatherStack PHP Class: Retrieve weather information from WeatherStack API

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 184 All time: 8,670 This week: 39Up
Version License PHP version Categories
weatherstack 1.0.0GNU General Publi...5PHP 5, Web services, Geography
Description 

Author

This class can retrieve weather information from WeatherStack API.

It can send HTTP requests to the WeatherStack API Web server to retrieve several types of details about the weather of a location.

Currently it can return the current date weather information, historical weather information for past dates, weather forecast for future dates, and autocomplete the names of locations for which the weather is available.

Innovation Award
PHP Programming Innovation award nominee
September 2019
Number 3
Weather information is useful to know what is the expected weather for a region in a future date so people can get prepared.

However, in some cases it is also useful to know what was the weather of that region in a past date.

This class can provide past weather information using the WeatherStack API.

Manuel Lemos
Picture of Dave Smith
  Performance   Level  
Name: Dave Smith is available for providing paid consulting. Contact Dave Smith .
Classes: 51 packages by
Country: United States United States
Age: 59
All time rank: 608 in United States United States
Week rank: 178 Down22 in United States United States Down
Innovation award
Innovation award
Nominee: 32x

Winner: 7x

Example

<?php
/*
example usage
weatherStack ver 1.0

You must get an API key from https://weatherstack.com/product
and enter it in the weatherstack.class.php file
*/

//turning off low level notices
error_reporting(E_ALL ^ E_NOTICE);

//instantiate the class
include('weatherstack.class.php');
$weather = new weatherStack();

//set the end point to use
//free plan uses the 'current' endpoint
//we can set it with 'current' or 'c' shorthand
$weather->setEndPoint('c');

//set the query parameter
$weather->setParam('query','New York');

//optionally set the units
$weather->setParam('units','f');

//get the response
$weather->getResponse();

//show specific response data
echo 'The current temperature in '.$weather->response->location->name.', '
   
.$weather->response->location->region.' is '
   
.$weather->response->current->temperature
   
.' degrees ('.$weather->response->request->unit.')';

echo
'<hr>';

//displaying the full response
echo '<pre>';
var_dump($weather->response);
echo
'<pre>';

/*
Premium plans are available that allow access to more endpoints.
You can see what is available at https://weatherstack.com/product.
*/
?>


  Files folder image Files (3)  
File Role Description
Accessible without login Plain text file example.php Example Example Usage
Accessible without login Plain text file license.txt Lic. License
Plain text file weatherstack.class.php Class Main Class

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:184
This week:0
All time:8,670
This week:39Up
User Comments (2)
Well documented and works as described.
4 years ago (Rick Ruggiero)
70%StarStarStarStar
Cool implementation.
5 years ago (David Domingues)
45%StarStarStar