WeatherHistory.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. /**
  3. * OpenWeatherMap-PHP-API — A php api to parse weather data from http://www.OpenWeatherMap.org .
  4. *
  5. * @license MIT
  6. *
  7. * Please see the LICENSE file distributed with this source code for further
  8. * information regarding copyright and licensing.
  9. *
  10. * Please visit the following links to read about the usage policies and the license of
  11. * OpenWeatherMap before using this class:
  12. *
  13. * @see http://www.OpenWeatherMap.org
  14. * @see http://www.OpenWeatherMap.org/terms
  15. * @see http://openweathermap.org/appid
  16. */
  17. use Cmfcmf\OpenWeatherMap;
  18. require_once __DIR__ . '/bootstrap.php';
  19. // Language of data (try your own language here!):
  20. $lang = 'en';
  21. // Units (can be 'metric' or 'imperial' [default]):
  22. $units = 'metric';
  23. // Get OpenWeatherMap object. Don't use caching (take a look into Example_Cache.php to see how it works).
  24. $owm = new OpenWeatherMap($myApiKey);
  25. // Example 1: Get hourly weather history between 2014-01-01 and today.
  26. $history = $owm->getWeatherHistory('Berlin', new \DateTime('2014-01-01'), new \DateTime('now'), 'hour', $units, $lang);
  27. foreach ($history as $weather) {
  28. echo 'Average temperature at '.$weather->time->format('d.m.Y H:i').': '.$weather->temperature."\n\r<br />";
  29. }