Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


hello everyone. im working on a js

hello everyone. im working on a js

hello everyone. im working on a js

hello everyone.
im working on a json from this site. https://btc-e.com/api/3/ticker/btc_usd
im trying to get the "last" key and
im trying to echo my own premiunm exchange rate.by getting 10% of the last key and add it up to the last key
my codes was like this
$url = "https://btc-e.com/api/3/ticker/btc_usd";
$fileGet = file_get_contents($url);
$json = json_decode($fileGet, TRUE);
$json = $json["ticker"]["last"];
$premium = 10; //in percentage
$premium = $premium / 100;
$dollar_amount = $premium * $json;
$customer_price = $json + $dollar_amount;
echo $customer_price;
there was no error indicated.but it just printed "0" on the screen.
please help. i dont know where something does wrong.

but everything work fine to line 4 $json=$json["ticker"]["last"]; because it print the correct last ticker on the browser.

RE: hello everyone. im working on a js


"ticker" ? Are you sure ? It looks more like $json["btc_usd"]["last"] to me.


RE: hello everyone. im working on a js

There is no "ticker" index in that json array.

So you should be getting an Undefined Index Notice because there no addressable item there. But your PHP may be set to suppress notices.

To see exactly what the array looks like and be able to address it correctly, its always a good idea to print it out. You can use print_r() to do so.


$json = json_decode($fileGet, TRUE);
echo "<pre>" . print_r($json,1) . "</pre>"; 

This should print out:

    [btc_usd] => Array
            [high] => 2486.96
            [low] => 2379.112
            [avg] => 2433.036
            [vol] => 8576408.53547
            [vol_cur] => 3526.96822
            [last] => 2414.001
            [buy] => 2415.99
            [sell] => 2414.001
            [updated] => 1498927868


So as feherke points out you should be addressing $json['btc_usd']['last']

Phil AKA Vacunita
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close