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 forecast for the next 10 days for Berlin.
39 $forecast = $owm->getWeatherForecast('Berlin', $units, $lang, '', 10);
40 echo "EXAMPLE 1<hr />\n\n\n";
42 echo "City: " . $forecast->city->name;
44 echo "LastUpdate: " . $forecast->lastUpdate->format('d.m.Y H:i');
46 echo "Sunrise : " . $forecast->sun->rise->format("H:i:s") . " Sunset : " . $forecast->sun->set->format("H:i:s");
50 foreach ($forecast as $weather) {
51 // Each $weather contains a Cmfcmf\ForecastWeather object which is almost the same as the Cmfcmf\Weather object.
52 // Take a look into 'Examples_Current.php' to see the available options.
53 echo "Weather forecast at " . $weather->time->day->format('d.m.Y') . " from " . $weather->time->from->format('H:i') . " to " . $weather->time->to->format('H:i');
55 echo $weather->temperature;
61 // Example 2: Get forecast for the next 3 days for Berlin.
62 $forecast = $owm->getWeatherForecast('Berlin', $units, $lang, '', 3);
63 echo "EXAMPLE 2<hr />\n\n\n";
65 foreach ($forecast as $weather) {
66 echo "Weather forecast at " . $weather->time->day->format('d.m.Y') . " from " . $weather->time->from->format('H:i') . " to " . $weather->time->to->format('H:i') . "<br />";
67 echo $weather->temperature . "<br />\n";