Skip to content

Commit 1784064

Browse files
committed
Added example call.
1 parent 72ca319 commit 1784064

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

README.md

+31
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,37 @@ For example code and how to use this api, please take a look into `Examples.php`
88

99
**Notice:** This api is not made by OpenWeatherMap, nor their offical php api.
1010

11+
Example call
12+
============
13+
```php
14+
<?php
15+
use cmfcmf\OpenWeatherMap;
16+
use cmfcmf\OpenWeatherMap\Exception as OWMException;
17+
18+
require('cmfcmf/OpenWeatherMap.php');
19+
20+
// Language of data (try your own language here!):
21+
$lang = 'de';
22+
23+
// Units (can be 'metric' or 'imperial' [default]):
24+
$units = 'metric';
25+
26+
// Get OpenWeatherMap object. Don't use caching (take a look into Example_Cache.php to see how it works).
27+
$owm = new OpenWeatherMap();
28+
29+
try {
30+
$weather = $owm->getWeather('Berlin', $units, $lang);
31+
} catch(OWMException $e) {
32+
echo 'OpenWeatherMap exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').';
33+
echo "<br />\n";
34+
} catch(\Exception $e) {
35+
echo 'General exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').';
36+
echo "<br />\n";
37+
}
38+
39+
echo $weather->temperature;
40+
```
41+
1142
License
1243
=======
1344
MIT — Please see the [LICENSE file](https://github.com/cmfcmf/OpenWeatherMap-PHP-Api/blob/master/LICENSE) distributed with this source code for further information regarding copyright and licensing.

0 commit comments

Comments
 (0)