Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) die(); // Настройки API $apiKey = "f5af0830-4836-4252-ab64-27855f0c3e4c"; // Замените на ваш API-ключ $latitude = "55.75396"; // Широта Москвы $longitude = "37.620393"; // Долгота Москвы // Настройки запроса $opts = array( 'http' => array( 'method' => 'GET', 'header' => 'X-Yandex-Weather-Key: ' . $apiKey ) ); $context = stream_context_create($opts); // URL запроса к API Яндекс.Погоды $url = "https://api.weather.yandex.ru/v2/forecast?lat={$latitude}&lon={$longitude}"; // Получение данных через file_get_contents $response = file_get_contents($url, false, $context); // Парсинг JSON $data = json_decode($response, true); // Проверка наличия данных if (isset($data["fact"])) { $arResult["WEATHER"] = [ "temperature" => $data["fact"]["temp"], "condition" => $data["fact"]["condition"], "humidity" => $data["fact"]["humidity"], "wind_speed" => $data["fact"]["wind_speed"] ]; } else { $arResult["WEATHER"] = null; // Ошибка при получении данных } echo $file; // Подключение шаблона $this->IncludeComponentTemplate(); ?>
Copy Clear