V
V
vladpenziy132020-04-14 19:00:02
PHP
vladpenziy13, 2020-04-14 19:00:02

How to use api in php?

The essence of the question is how to display certain information from the api, for example, only the dollar exchange rate here is the code:
<?php
$url = ' https://api.privatbank.ua/p24api/pubinfo?exchange&... ';
$json_response = file_get_contents($url);
$response = json_decode($json_response);
foreach ($response as $item){
var_dump($item);
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
TostPOST, 2020-04-14
@vladpenziy13

$url = 'https://api.privatbank.ua/p24api/pubinfo?exchange&json&coursid=11';
$json_response = file_get_contents($url);
$response = json_decode($json_response,true);
$dollarcost = $response[0]['buy'];
 echo $dollarcost;

M
Mors Clamor, 2020-04-14
@66demon666

In order for you to get not only the dollar rate, but namely WORK WITH API, google about curl. It's actually easier than it looks at first glance.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question