S
S
Sergey432018-10-19 10:57:49
PHP
Sergey43, 2018-10-19 10:57:49

How to display price from json in php?

Good afternoon. There is this code:

<?php if(in_category(4)) :
$tick = file_get_contents('https://api.coinmarketcap.com/v1/ticker/bitcoin?convert=RUB');
$data = json_decode($tick, TRUE);

$price = $data[0]["price_rub"];
echo "<div>Текущая цена: ".$price." РУБ</div>";
?>
<?php endif; ?>

It safely displays the cost in the rubric. But soon this api version will stop working, and there will be the following one:
https://api.coinmarketcap.com/v2/ticker/1/?convert=RUB
Not enough knowledge, how to correct the code so that the cost is displayed? Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Proskurin, 2018-10-19
@Sergey43

$price = $data["data"]["quotes"]["RUB"]["price"];
echo "<div>Текущая цена: ".$price." РУБ</div>";

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question