PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Dave Smith   WeatherStack PHP Class   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example Usage
Class: WeatherStack PHP Class
Retrieve weather information from WeatherStack API
Author: By
Last change:
Date: 4 years ago
Size: 1,186 bytes


Class file image Download
example usage
weatherStack ver 1.0

You must get an API key from
and enter it in the weatherstack.class.php file

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

//instantiate the class
$weather = new weatherStack();

//set the end point to use
//free plan uses the 'current' endpoint
//we can set it with 'current' or 'c' shorthand

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

//optionally set the units

//get the response

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


//displaying the full response
echo '<pre>';

Premium plans are available that allow access to more endpoints.
You can see what is available at