Skip to content

A PHP API to parse weather data and weather history from OpenWeatherMap.org.

License

Notifications You must be signed in to change notification settings

davetosh/OpenWeatherMap-PHP-Api

This branch is 111 commits behind cmfcmf/OpenWeatherMap-PHP-API:main.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

9222160 · Mar 22, 2018
Jan 21, 2018
Jan 21, 2018
Aug 30, 2017
Mar 4, 2018
Dec 9, 2015
Dec 9, 2015
Aug 6, 2017
Mar 22, 2018
Mar 4, 2018
Mar 4, 2018
Mar 4, 2018
Mar 4, 2018
Jan 2, 2017

Repository files navigation

OpenWeatherMap PHP API

A php API to retrieve and parse global weather data from OpenWeatherMap.org. This library aims to normalise the provided data and remove some inconsistencies. This library is neither maintained by OpenWeatherMap nor their official PHP API.

Build Status Scrutinizer Quality Score codecov SensioLabsInsight

Installation

This library can be found on Packagist. The recommended way to install and use this is through Composer.

composer require "cmfcmf/openweathermap-php-api"

Example call

<?php
use Cmfcmf\OpenWeatherMap;
use Cmfcmf\OpenWeatherMap\Exception as OWMException;

// Must point to composer's autoload file.
require 'vendor/autoload.php';

// Language of data (try your own language here!):
$lang = 'de';

// Units (can be 'metric' or 'imperial' [default]):
$units = 'metric';

// Create OpenWeatherMap object. 
// Don't use caching (take a look into Examples/Cache.php to see how it works).
$owm = new OpenWeatherMap('YOUR-API-KEY');

try {
    $weather = $owm->getWeather('Berlin', $units, $lang);
} catch(OWMException $e) {
    echo 'OpenWeatherMap exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').';
} catch(\Exception $e) {
    echo 'General exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').';
}

echo $weather->temperature;

For more example code and instructions on how to use this library, please take a look into the Examples folder. Make sure to get an API Key from http://home.openweathermap.org/ and put it into Examples/ApiKey.ini.

  • CurrentWeather.php Shows how to receive the current weather.
  • WeatherForecast.php Shows how to receive weather forecasts.
  • WeatherHistory.php Shows how to receive weather history.
  • Cache.php Shows how to implement and use a cache.

Contribute!

I'm happy about every pull request or issue you find and open to help making this API more awesome.

You can use Vagrant to kick-start your development. Simply run vagrant up and vagrant ssh to start a PHP VM.

License

MIT — Please see the LICENSE file distributed with this source code for further information regarding copyright and licensing.

Please check out the following official links to read about the terms, pricing and license of OpenWeatherMap before using the service.

About

A PHP API to parse weather data and weather history from OpenWeatherMap.org.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%