A
A
Artem Gvozdev2020-05-30 20:37:48
PHP
Artem Gvozdev, 2020-05-30 20:37:48

How to make weather forecast dynamically in php?

Hello!
For the weather informer, I use the service api - https://openweathermap.org/
The code is like this

<?
$apiKey = "key";
$cityId = "Минск";
$googleApiUrl = "http://api.openweathermap.org/data/2.5/weather?q=" . $cityId . "&lang=ru&units=metric&APPID=" . $apiKey;
$ch = curl_init();

curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $googleApiUrl);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response);
$currentTime = time();
?>

The question is, how can I get the city dynamically?
I want to make static pages with cities on wordpress and load the weather forecast there

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question