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

BiberacherAndreas/OpenWeatherMap-PHP-Api

 
 

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 license release codecov Scrutinizer Quality Score
SensioLabsInsight

Installation

This library can be found on Packagist. The recommended way to install and use it 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.

Contributing

I'm happy about every pull request or issue you find and open to help make 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 with all dependencies included.

Support me

If you like my work, I'd really appreciate you buying me a coffee. Your donations help me put more time into Open-Source software development.

Buy Me a Coffee at ko-fi.com

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%