Created
September 4, 2015 06:38
-
-
Save Ibochkarev/70f5b17ad1bc67b573ad to your computer and use it in GitHub Desktop.
Openweathermap weather city
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//q = Name city | |
$curl = curl_init("http://api.openweathermap.org/data/2.5/weather?q=calp&units=metric&mode=xml&lang=ru"); | |
curl_setopt($curl, CURLOPT_FAILONERROR, true); | |
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false); | |
curl_setopt($curl, CURLOPT_HEADER, false); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 1); | |
$buffer = curl_exec($curl); | |
curl_close($curl); | |
$xml = new SimpleXMLElement($buffer); | |
$city = $xml->city[name]; | |
$temperarure = $xml->temperature[value]; | |
$weather_id = $xml->weather[number]; | |
$weather_icon = $xml->weather[icon]; | |
$weather_type = $xml->weather[value]; | |
$temperarure = round($temperarure); | |
if ($temperarure>0) {$temperarure='+'.$temperarure;} | |
echo "<strong>$city</strong>"; | |
echo (" <img src=\"/assets/images/weather/$weather_icon.svg\" height=\"35\" alt=\"$weather_id\" title=\"$weather_type\" > <span>$temperarure<sup>o</sup>C</span>"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment