3 * OpenWeatherMap-PHP-API — A php api to parse weather data from http://www.OpenWeatherMap.org .
7 * Please see the LICENSE file distributed with this source code for further
8 * information regarding copyright and licensing.
10 * Please visit the following links to read about the usage policies and the license of
11 * OpenWeatherMap before using this class:
13 * @see http://www.OpenWeatherMap.org
14 * @see http://www.OpenWeatherMap.org/terms
15 * @see http://openweathermap.org/appid
18 use Cmfcmf\OpenWeatherMap;
20 if (file_exists('../vendor/autoload.php')) {
21 // Library is not part of a project. "composer install" was executed directly on this library's composer file.
22 require('../vendor/autoload.php');
24 // Library is part of a project.
25 /** @noinspection PhpIncludeInspection */
26 require('../../../autoload.php');
29 // Language of data (try your own language here!):
32 // Units (can be 'metric' or 'imperial' [default]):
35 // Get OpenWeatherMap object. Don't use caching (take a look into Example_Cache.php to see how it works).
36 $owm = new OpenWeatherMap();
38 // Example 1: Get hourly weather history between 2014-01-01 and today.
39 $history = $owm->getWeatherHistory('Berlin', new \DateTime('2014-01-01'), new \DateTime('now'), 'hour', $units, $lang);
41 foreach ($history as $weather) {
42 echo "Average temperature at " . $weather->time->format('d.m.Y H:i') . ": " . $weather->temperature . "\n\r<br />";