1

How can I get variables "price_usd" and "price_btc" from JSON url https://api.coinmarketcap.com/v1/ticker/ethereum/? I wrote a script but nothing happens.

 <?php
$tick = file_get_contents('https://api.coinmarketcap.com/v1/ticker/ethereum/'); 
$url = $tick;
$json = file_get_contents($url);
$data = json_decode($json, TRUE);

$usd = $data[0]["price_usd"];
echo $usd;
?>
halfer
  • 19,824
  • 17
  • 99
  • 186
jack smith
  • 7
  • 1
  • 3

2 Answers2

3

Your code use a file_get_contents twice, look at would be:

<?php
$tick = file_get_contents('https://api.coinmarketcap.com/v1/ticker/ethereum/');
$url = $tick;
echo $url;
//$json = file_get_contents($url);
$data = json_decode($tick, TRUE);

$usd = $data[0]["price_usd"];
echo $usd;
?>
Álvaro Touzón
  • 1,247
  • 1
  • 8
  • 21
0

Try this

<?php
$json = file_get_contents('https://api.coinmarketcap.com/v1/ticker/ethereum/'); 
$data = json_decode($json);
var_dump($data[0]->price_usd);

?>
Jaydeep Rajput
  • 3,605
  • 17
  • 35