Երբեմն պետք է գալիս տեղադրել եղանակային տվյալներ կայքում
Հիմա կնկարագրեմ ամբողջ պրոցեսը սկսած կայքի հյուրի քաղաքի որոշումից մինչև եղանակի ցուցադրում.
Օգտվում ենք 2 API-ներից
1: http://api.easyjquery.com
$ip = $_SERVER[‘REMOTE_ADDR’];//որոշում ենք կայքի այցելուի ip հասցեն
և $_GET ով փոխանցում ենք հետևյալ կերպ
$json =file_get_contents("http://api.easyjquery.com/ips/?ip=".$ip."&full=true");
Այժմ $json փոփոհականի մեջ պարունակվում է ամբողջ աշխարհագրական ինֆորմացիան .
Այս տվյալների հետ հեշտ աշխատելու համար վերածում ենք օբյեկտի
$data = json_decode($json);
Ստացվում է էսպիսի մի բան
stdClass Object ( [IP] => 37.190.36.56 [ContinentCode] => EU [ContinentName] => Europe [CountryCode2] => RU [CountryCode3] => RUS [Country] => RU [CountryName] => Russia [RegionName] => Moscow City [CityName] => Moscow [CityLatitude] => 55.7522 [CityLongitude] => 37.6156 [CountryLatitude] => 60 [CountryLongitude] => 47 [LocalTimeZone] => Europe/Moscow [REMOTE_ADDR] => 46.70.0.106 [HTTP_X_FORWARDED_FOR] => 89.185.234.250 [CallingCode] => 7 [Population] => 140,041,247 (9) [AreaSqKm] => 17,098,242 (1) [GDP_USD] => 2.266 Trillion (6) [Capital] => Moscow [Electrical] => 220 V,50 Hz Type F Type C [Languages] => Russian, many minority languages [Currency] => Russian Federation R (RUB) [Flag] => http://api.easyjquery.com/proips/flags/RU.jpg )
Առաջին մասը ավարտված է
$data->CityName փոփոխականում ունենք քաղաքի անվանումը
Գնում ենք http://www.worldweatheronline.com ,գրանցվում,ստանում մեր անձնական բանալին(key-ը)
$key=”pz6jejmy7yxpddd9cuj2sz72″;
Որպեսզի ստանանք եղանակային տվյալները անում ենք հետևյալը
$weatherUrl ="http://api.worldweatheronline.com/free/v1/weather.ashx?q=".$data->CityName."&format=json&num_of_days=5&key=".$key; $weather =file_get_contents($weatherUrl);
Վերածում ենք json ֆորմատի պատասխանը օբյեկտի
$weatherInfo = json_decode($weather);
$weatherInfo օբյեկտում ունենք ինֆորմացիա մոտակա 5 օրվա եղանակի մասին.
Ստորև ամբողջ ինֆորմացիան.
stdClass Object ( [data] => stdClass Object ( [current_condition] => Array ( [0] => stdClass Object ( [cloudcover] => 0 [humidity] => 41 [observation_time] => 10:26 AM [precipMM] => 0.0 [pressure] => 1016 [temp_C] => 22 [temp_F] => 72 [visibility] => 10 [weatherCode] => 113 [weatherDesc] => Array ( [0] => stdClass Object ( [value] => Sunny ) ) [weatherIconUrl] => Array ( [0] => stdClass Object ( [value] => http://www.worldweatheronline.com/images/wsymbols01_png_64/wsymbol_0001_sunny.png ) ) [winddir16Point] => SW [winddirDegree] => 230 [windspeedKmph] => 11 [windspeedMiles] => 7 ) ) [request] => Array ( [0] => stdClass Object ( [query] => Moscow, Russia [type] => City ) ) [weather] => Array ( [0] => stdClass Object ( [date] => 2013-05-30 [precipMM] => 0.0 [tempMaxC] => 24 [tempMaxF] => 75 [tempMinC] => 13 [tempMinF] => 55 [weatherCode] => 113 [weatherDesc] => Array ( [0] => stdClass Object ( [value] => Sunny ) ) [weatherIconUrl] => Array ( [0] => stdClass Object ( [value] => http://www.worldweatheronline.com/images/wsymbols01_png_64/wsymbol_0001_sunny.png ) ) [winddir16Point] => SW [winddirDegree] => 234 [winddirection] => SW [windspeedKmph] => 9 [windspeedMiles] => 6 ) [1] => stdClass Object ( [date] => 2013-05-31 [precipMM] => 0.0 [tempMaxC] => 26 [tempMaxF] => 78 [tempMinC] => 15 [tempMinF] => 59 [weatherCode] => 113 [weatherDesc] => Array ( [0] => stdClass Object ( [value] => Sunny ) ) [weatherIconUrl] => Array ( [0] => stdClass Object ( [value] => http://www.worldweatheronline.com/images/wsymbols01_png_64/wsymbol_0001_sunny.png ) ) [winddir16Point] => ENE [winddirDegree] => 67 [winddirection] => ENE [windspeedKmph] => 11 [windspeedMiles] => 7 ) [2] => stdClass Object ( [date] => 2013-06-01 [precipMM] => 0.0 [tempMaxC] => 26 [tempMaxF] => 79 [tempMinC] => 14 [tempMinF] => 57 [weatherCode] => 113 [weatherDesc] => Array ( [0] => stdClass Object ( [value] => Sunny ) ) [weatherIconUrl] => Array ( [0] => stdClass Object ( [value] => http://www.worldweatheronline.com/images/wsymbols01_png_64/wsymbol_0001_sunny.png ) ) [winddir16Point] => ENE [winddirDegree] => 77 [winddirection] => ENE [windspeedKmph] => 16 [windspeedMiles] => 10 ) [3] => stdClass Object ( [date] => 2013-06-02 [precipMM] => 2.9 [tempMaxC] => 25 [tempMaxF] => 77 [tempMinC] => 14 [tempMinF] => 57 [weatherCode] => 353 [weatherDesc] => Array ( [0] => stdClass Object ( [value] => Light rain shower ) ) [weatherIconUrl] => Array ( [0] => stdClass Object ( [value] => http://www.worldweatheronline.com/images/wsymbols01_png_64/wsymbol_0009_light_rain_showers.png ) ) [winddir16Point] => E [winddirDegree] => 84 [winddirection] => E [windspeedKmph] => 15 [windspeedMiles] => 9 ) [4] => stdClass Object ( [date] => 2013-06-03 [precipMM] => 0.0 [tempMaxC] => 27 [tempMaxF] => 80 [tempMinC] => 13 [tempMinF] => 55 [weatherCode] => 113 [weatherDesc] => Array ( [0] => stdClass Object ( [value] => Sunny ) ) [weatherIconUrl] => Array ( [0] => stdClass Object ( [value] => http://www.worldweatheronline.com/images/wsymbols01_png_64/wsymbol_0001_sunny.png ) ) [winddir16Point] => ENE [winddirDegree] => 61 [winddirection] => ENE [windspeedKmph] => 11 [windspeedMiles] => 7 ) ) ) )
Բարև Ձեզ, Ես մի խնդրանք ունեմ, Ես ունեմ կայք, ու շատ շնորհակալ կլնինեմ եթե ասեք ինչպես տեղադրեմ ձեր ՞ՙ՚Եղանակի տեսություն Ձեր կայքում՞ հոդվածի կոդը. իմ կայքի հասցեն է, խնդրում եմ ասեք կա հնարավորություն այն տեղադրել իմ կայքում: www.machoars.ru նախապես շնորհակալություն
Բարև Ձեզ. Կոդը կարող եք տեղադրել Ձեր կայքի կոդի ցանկացած մասում. Կատարելով վերը նված գործողությունները ու պարզապես echo $weatherInfo->data->weather[0]->weatherDesc[0]->value//եղանակի նկարագրություն -արևոտ echo $weatherInfo->data->weather[0]->weatherIconUrl[0]->value//նկարը-արևի նկար echo $weatherInfo->data->weather[0]->tempMaxC //մաքսիմալ ջերմաստիճան echo $weatherInfo->data->weather[0]->tempMinC //մինիմալ ջերմաստիճան
գրեք Ձեր էլ. հասցեն, կամ գրեք իմ էլ. հասցեին եթե դժվար չէ. Մերսի
Բարև ձեզ կարող եք օգնել որ այս կոդը տեղադրեմ բլոգգերում եթե հնարավոր է