1414 * @see http://www.OpenWeatherMap.org/terms
1515 * @see http://openweathermap.org/appid
1616 */
17-
1817use Cmfcmf \OpenWeatherMap ;
1918use Cmfcmf \OpenWeatherMap \Exception as OWMException ;
2019
2120if (file_exists ('../vendor/autoload.php ' )) {
2221 // Library is not part of a project. "composer install" was executed directly on this library's composer file.
23- require ( '../vendor/autoload.php ' ) ;
22+ require '../vendor/autoload.php ' ;
2423} else {
2524 // Library is part of a project.
2625 /** @noinspection PhpIncludeInspection */
27- require ( '../../../autoload.php ' ) ;
26+ require '../../../autoload.php ' ;
2827}
2928
3029// Load the app configuration
6362echo $ weather ->temperature ->getUnit ();
6463echo "<br /> \n" ;
6564
66- /**
65+ /*
6766 * In the example above we're using a "shortcut". OpenWeatherMap returns the minimum temperature of a day,
6867 * the maximum temperature and the temperature right now. If you don't specify which temperature you want, it will default
6968 * to the current temperature. See below how to access the other values. Notice that each of them has implemented the methods
7069 * "getFormatted()", "getValue()", "getUnit()".
7170 */
7271
7372// Returns the current temperature:
74- echo " Current: " . $ weather ->temperature ->now ;
73+ echo ' Current: ' . $ weather ->temperature ->now ;
7574echo "<br /> \n" ;
7675
7776// Returns the minimum temperature:
78- echo " Minimum: " . $ weather ->temperature ->min ;
77+ echo ' Minimum: ' . $ weather ->temperature ->min ;
7978echo "<br /> \n" ;
8079
8180// Returns the maximum temperature:
82- echo " Maximum: " . $ weather ->temperature ->max ;
81+ echo ' Maximum: ' . $ weather ->temperature ->max ;
8382echo "<br /> \n" ;
8483
85- /**
84+ /*
8685 * When speaking about "current" and "now", this means when the weather data was last updated. You can get this
8786 * via a DateTime object:
8887 */
89- echo " Last update: " . $ weather ->lastUpdate ->format ('r ' );
88+ echo ' Last update: ' . $ weather ->lastUpdate ->format ('r ' );
9089echo "<br /> \n" ;
9190
9291// Example 2: Get current pressure and humidity in Hongkong.
9392$ weather = $ owm ->getWeather ('Hongkong ' , $ units , $ lang );
9493echo "<br /><br /> \n\n\nEXAMPLE 2<hr /> \n\n\n" ;
9594
96- /**
95+ /*
9796 * You can use the methods above to only get the value or the unit.
9897 */
9998
100- echo " Pressure: " . $ weather ->pressure ;
99+ echo ' Pressure: ' . $ weather ->pressure ;
101100echo "<br /> \n" ;
102- echo " Humidity: " . $ weather ->humidity ;
101+ echo ' Humidity: ' . $ weather ->humidity ;
103102echo "<br /> \n" ;
104103
105104// Example 3: Get today's sunrise and sunset times.
106105echo "<br /><br /> \n\n\nEXAMPLE 3<hr /> \n\n\n" ;
107106
108- /**
107+ /*
109108 * These functions return a DateTime object.
110109 */
111110
112- echo " Sunrise: " . $ weather ->sun ->rise ->format ('r ' );
111+ echo ' Sunrise: ' . $ weather ->sun ->rise ->format ('r ' );
113112echo "<br /> \n" ;
114- echo " Sunset: " . $ weather ->sun ->set ->format ('r ' );
113+ echo ' Sunset: ' . $ weather ->sun ->set ->format ('r ' );
115114echo "<br /> \n" ;
116115
117116// Example 4: Get current temperature from coordinates (Greenland :-) ).
118117$ weather = $ owm ->getWeather (array ('lat ' => 77.73038 , 'lon ' => 41.89604 ), $ units , $ lang );
119118echo "<br /><br /> \n\n\nEXAMPLE 4<hr /> \n\n\n" ;
120119
121- echo " Temperature: " . $ weather ->temperature ;
120+ echo ' Temperature: ' . $ weather ->temperature ;
122121echo "<br /> \n" ;
123122
124123// Example 5: Get current temperature from city id. The city is an internal id used by OpenWeatherMap. See example 6 too.
125124$ weather = $ owm ->getWeather (2172797 , $ units , $ lang );
126125echo "<br /><br /> \n\n\nEXAMPLE 5<hr /> \n\n\n" ;
127126
128- echo " City: " . $ weather ->city ->name ;
127+ echo ' City: ' . $ weather ->city ->name ;
129128echo "<br /> \n" ;
130129
131- echo " Temperature: " . $ weather ->temperature ;
130+ echo ' Temperature: ' . $ weather ->temperature ;
132131echo "<br /> \n" ;
133132
134133// Example 6: Get information about a city.
135134$ weather = $ owm ->getWeather ('Paris ' , $ units , $ lang );
136135echo "<br /><br /> \n\n\nEXAMPLE 6<hr /> \n\n\n" ;
137136
138- echo " Id: " . $ weather ->city ->id ;
137+ echo ' Id: ' . $ weather ->city ->id ;
139138echo "<br /> \n" ;
140139
141- echo " Name: " . $ weather ->city ->name ;
140+ echo ' Name: ' . $ weather ->city ->name ;
142141echo "<br /> \n" ;
143142
144- echo " Lon: " . $ weather ->city ->lon ;
143+ echo ' Lon: ' . $ weather ->city ->lon ;
145144echo "<br /> \n" ;
146145
147- echo " Lat: " . $ weather ->city ->lat ;
146+ echo ' Lat: ' . $ weather ->city ->lat ;
148147echo "<br /> \n" ;
149148
150- echo " Country: " . $ weather ->city ->country ;
149+ echo ' Country: ' . $ weather ->city ->country ;
151150echo "<br /> \n" ;
152151
153152// Example 7: Get wind information.
154153echo "<br /><br /> \n\n\nEXAMPLE 7<hr /> \n\n\n" ;
155154
156- echo " Speed: " . $ weather ->wind ->speed ;
155+ echo ' Speed: ' . $ weather ->wind ->speed ;
157156echo "<br /> \n" ;
158157
159- echo " Direction: " . $ weather ->wind ->direction ;
158+ echo ' Direction: ' . $ weather ->wind ->direction ;
160159echo "<br /> \n" ;
161160
162- /**
161+ /*
163162 * For speed and direction there is a description available, which isn't always translated.
164163 */
165164
166- echo " Speed: " . $ weather ->wind ->speed ->getDescription ();
165+ echo ' Speed: ' . $ weather ->wind ->speed ->getDescription ();
167166echo "<br /> \n" ;
168167
169- echo " Direction: " . $ weather ->wind ->direction ->getDescription ();
168+ echo ' Direction: ' . $ weather ->wind ->direction ->getDescription ();
170169echo "<br /> \n" ;
171170
172171// Example 8: Get information about the clouds.
173172echo "<br /><br /> \n\n\nEXAMPLE 8<hr /> \n\n\n" ;
174173
175174// The number in braces seems to be an indicator how cloudy the sky is.
176- echo " Clouds: " . $ weather ->clouds ->getDescription () . " ( " . $ weather ->clouds . " ) " ;
175+ echo ' Clouds: ' . $ weather ->clouds ->getDescription (). ' ( ' . $ weather ->clouds . ' ) ' ;
177176echo "<br /> \n" ;
178177
179178// Example 9: Get information about precipitation.
180179echo "<br /><br /> \n\n\nEXAMPLE 9<hr /> \n\n\n" ;
181180
182- echo " Precipation: " . $ weather ->precipitation ->getDescription () . " ( " . $ weather ->precipitation . " ) " ;
181+ echo ' Precipation: ' . $ weather ->precipitation ->getDescription (). ' ( ' . $ weather ->precipitation . ' ) ' ;
183182echo "<br /> \n" ;
184183
185184// Example 10: Show copyright notice. WARNING: This is no offical text. This hint was created regarding to http://www.http://openweathermap.org/copyright .
191190// Example 11: Get raw xml data.
192191echo "<br /><br /> \n\n\nEXAMPLE 11<hr /> \n\n\n" ;
193192
194- echo " <pre><code> " . htmlspecialchars ($ owm ->getRawWeatherData ('Berlin ' , $ units , $ lang , null , 'xml ' )) . " </code></pre> " ;
193+ echo ' <pre><code> ' . htmlspecialchars ($ owm ->getRawWeatherData ('Berlin ' , $ units , $ lang , null , 'xml ' )). ' </code></pre> ' ;
195194echo "<br /> \n" ;
196195
197196// Example 12: Get raw json data.
198197echo "<br /><br /> \n\n\nEXAMPLE 12<hr /> \n\n\n" ;
199198
200- echo " <code> " . htmlspecialchars ($ owm ->getRawWeatherData ('Berlin ' , $ units , $ lang , null , 'json ' )) . " </code> " ;
199+ echo ' <code> ' . htmlspecialchars ($ owm ->getRawWeatherData ('Berlin ' , $ units , $ lang , null , 'json ' )). ' </code> ' ;
201200echo "<br /> \n" ;
202201
203202// Example 13: Get raw html data.
211210
212211// Try wrong city name.
213212try {
214- $ weather = $ owm ->getWeather (" ThisCityNameIsNotValidAndDoesNotExist " , $ units , $ lang );
213+ $ weather = $ owm ->getWeather (' ThisCityNameIsNotValidAndDoesNotExist ' , $ units , $ lang );
215214} catch (OWMException $ e ) {
216- echo $ e ->getMessage () . ' (Code ' . $ e ->getCode () . '). ' ;
215+ echo $ e ->getMessage (). ' (Code ' . $ e ->getCode (). '). ' ;
217216 echo "<br /> \n" ;
218217}
219218
220219// Try invalid $query.
221220try {
222221 $ weather = $ owm ->getWeather (new \DateTime ('now ' ), $ units , $ lang );
223222} catch (\Exception $ e ) {
224- echo $ e ->getMessage () . ' (Code ' . $ e ->getCode () . '). ' ;
223+ echo $ e ->getMessage (). ' (Code ' . $ e ->getCode (). '). ' ;
225224 echo "<br /> \n" ;
226225}
227226
228227// Full error handling would look like this:
229228try {
230229 $ weather = $ owm ->getWeather (-1 , $ units , $ lang );
231230} catch (OWMException $ e ) {
232- echo 'OpenWeatherMap exception: ' . $ e ->getMessage () . ' (Code ' . $ e ->getCode () . '). ' ;
231+ echo 'OpenWeatherMap exception: ' . $ e ->getMessage (). ' (Code ' . $ e ->getCode (). '). ' ;
233232 echo "<br /> \n" ;
234233} catch (\Exception $ e ) {
235- echo 'General exception: ' . $ e ->getMessage () . ' (Code ' . $ e ->getCode () . '). ' ;
234+ echo 'General exception: ' . $ e ->getMessage (). ' (Code ' . $ e ->getCode (). '). ' ;
236235 echo "<br /> \n" ;
237236}
238237
239238// Example 15: Using an api key:
240239echo "<br /><br /> \n\n\nEXAMPLE 15<hr /> \n\n\n" ;
241240$ weather = $ owm ->getWeather ('Berlin ' , $ units , $ lang , $ myApiKey );
242- echo $ weather ->temperature . "\n" ;
243- echo "<br /> \n" ;
244-
241+ echo $ weather ->temperature ."\n" ;
242+ echo "<br /> \n" ;
0 commit comments