Displaying price in BTC based on USD exchange rate This is a pretty classic programming question, but I think it is a very common one for the Bitcoin community, and would be helpful to have the code publicly available.

My preference is for a php script.



Bitpay publishes it's exchange rates here: https://bitpay.com/api/rates

If an item is $10 USD, how would I do the following?

1) extract the BTC/USD exchange rate from the array at this URL
2) Define the price, then divide by the exchange rate
3) Display the BTC price in an HTML page?
Save the code to a PHP file in the web directory: 

&lt;?php  
  $url = "https://bitpay.com/api/rates";

  $json = file_get_contents($url);
  $data = json_decode($json, TRUE);

  $rate = $data[2]["rate"];   //$data[1] is outdated now, they have updated their json order. This new number 2 now fetches USD price. 
  $usd_price = 10;     # Let cost of elephant be 10$
  $bitcoin_price = round( $usd_price / $rate , 8 );
?&gt;

&lt;ul&gt;
   &lt;li&gt;Price: &lt;?=$usd_price ?&gt; $ / &lt;?=$bitcoin_price ?&gt; BTC
&lt;/ul&gt;