0

Im trying to extract the file from this url (http://chainz.cryptoid.info/cbx/api.dws?q=getdifficulty) which shows a number but I can't seem to display it. Is there a problem in my code or is it in the site that I'm getting it from?

Here's my code:

<?php 
$url = "http://chainz.cryptoid.info/cbx/api.dws?q=getdifficulty";
$data = json_decode(file_get_contents($url), true);
echo "$data";
?>

It only shows null, can you please help?

Once the above is being answered, I would like to try using a bigger content from this url (http://chainz.cryptoid.info/cbx/api.dws?q=lasttxs&a=5h9ZZpokW2P15yXr66MsHKknPvYmECvaDF)

Here's my code below:

<?php 
$url = "http://chainz.cryptoid.info/cbx/api.dws?q=lasttxs&a=5h9ZZpokW2P15yXr66MsHKknPvYmECvaDF";
$data = json_decode(file_get_contents($url), true);
$content = $data[0]; //trying to get the 1st row
$hash = $content['hash'];
echo "$hash";
?>

The code is not showing anything. Can you please help in displaying the value using php? Thanks

This code though is working ok:

<?php 
$url = "https://www.cryptonator.com/api/ticker/cbx-usd";
$data = json_decode(file_get_contents($url), true);
$ticker = $data['ticker'];
$latest_price = $ticker['price'];
echo "$latest_price";
?>
Benjamin
  • 47
  • 1
  • 5

2 Answers2

0

In the first example the data isn't returned as JSON, it's just a raw number. You can just use:

$data = file_get_contents($url);

Both of your other examples works fine for me.

iainn
  • 16,826
  • 9
  • 33
  • 40
  • I tried ' $data = file_get_contents($url);' but it didn't work. Just showing nothing. So you mean the 2nd code is working ok for you without no need for any editing? – Benjamin May 11 '16 at 14:27
0

It seems the codes are working ok using XAMMP but not when I'm using 000webhost. Weird.

Benjamin
  • 47
  • 1
  • 5