<p>Your question is a bit confusing but it sounds like you are asking how to get a currency amount worth of bitcoin.    </p>

<blockquote>
  <p>I want the user to be able to click the USD price and convert it to BTC instantly.    </p>
</blockquote>

<p>The answer is simple, division. </p>

<pre><code>&lt;?php
$url = "https://blockchain.info/stats?format=json";
$stats = json_decode(file_get_contents($url), true);
$btcValue = $stats['market_price_usd'];
$usdCost = 200;

$convertedCost = $usdCost / $btcValue;

echo $convertedCost;
?&gt;     
</code></pre>

<p><a href="http://phpfiddle.org/lite/code/cxsk-b62m" rel="nofollow">http://phpfiddle.org/lite/code/cxsk-b62m</a>     </p>

<blockquote>
  <p>(If it helps, im a noob sorry)    </p>
</blockquote>

<p>That's okay. If you're looking to learn more beginner related Bitcoin coding stuff check out this mega-thread at bitcointalk <a href="https://bitcointalk.org/index.php?topic=990348.0" rel="nofollow">https://bitcointalk.org/index.php?topic=990348.0</a>  It's mostly PHP and JavaScript examples. </p>

CC BY-SA 3.0
2016-08-31T17:32:28.810Z
I'll test it now, thank you very much man !!
Thomas Farley
CC BY-SA 3.0
2016-08-31T17:41:58.310Z
Yep, I suppose I can work with this, thanks buddy.
Thomas Farley
CC BY-SA 3.0
2016-08-31T00:47:10.740Z
2016-08-31T00:47:10.740Z
m1xolyd1an
<p>So, I have looked everywhere and no one seems to have this specific problem. </p>

<p>I have set up a e-commerce store that is accepting BTC, So far the users can only see the price of the product in USD, however, I want the user to be able to click the USD price and convert it to BTC instantly. Like you can on a blockchain.info transaction.</p>

<p>For example:</p>

<p><a href="https://i.sstatic.net/gRPY4.png" rel="nofollow noreferrer">Blockchain transaction conversion</a></p>

<p>So far, I have only been able to display the BTC price using Blockchain API.</p>

<p><strong>I want the same effect as Blockchain on my price, or atleast under it.</strong> </p>

<p><strong>(Snapshots of site below to give an idea of what I want)</strong></p>

<p><a href="https://i.sstatic.net/pmyD7.png" rel="nofollow noreferrer">My images</a></p>

<p>The code I have to display the BTC price (If it helps, im a noob sorry)</p>

<pre><code>&lt;?php

  $url = "https://blockchain.info/stats?format=json";
  $stats = json_decode(file_get_contents($url), true);

  echo $stats['market_price_usd'];

  ?&gt;
</code></pre>

<p>Price display:</p>

<pre><code>&lt;p class="Price"&gt;$200.50&lt;/p&gt;
</code></pre>

CC BY-SA 3.0
2016-08-30T21:20:11.423Z
It took me a bit to realize what your question is. Could you please make that clearer?
Murch
CC BY-SA 3.0
2016-08-30T22:16:33.117Z
See here https://github.com/miohtama/bitcoin-prices
Mikko Ohtamaa
CC BY-SA 3.0
2016-08-30T23:17:55.757Z
@SvenWilliamson Most of these seem irrelevant to the question.
Nick ODell
<exchange-rate><php>
USD to BTC conversion code
Thomas Farley
# USD to BTC conversion code

(Asked by: username_0 on 2016-08-30)

So, I have looked everywhere and no one seems to have this specific problem. 
I have set up a e-commerce store that is accepting BTC, So far the users can only see the price of the product in USD, however, I want the user to be able to click the USD price and convert it to BTC instantly. Like you can on a blockchain.info transaction.
For example:
Blockchain transaction conversion
So far, I have only been able to display the BTC price using Blockchain API.
I want the same effect as Blockchain on my price, or atleast under it. 
(Snapshots of site below to give an idea of what I want)
My images
The code I have to display the BTC price (If it helps, im a noob sorry)


Price display:
$200.50

**Tags:** exchange-rate, php

> **Comments:**
> **username_1**: It took me a bit to realize what your question is. Could you please make that clearer?  
> **username_2**: See here https://github.com/miohtama/bitcoin-prices  
> **username_3**: @SvenWilliamson Most of these seem irrelevant to the question.  

---

## 1 answers

### Answer by username_4 on 2016-08-31. Score: 0 | Accepted answer

Your question is a bit confusing but it sounds like you are asking how to get a currency amount worth of bitcoin.    

I want the user to be able to click the USD price and convert it to BTC instantly.    

The answer is simple, division. 
     

http://phpfiddle.org/lite/code/cxsk-b62m 

(If it helps, im a noob sorry)    

That's okay. If you're looking to learn more beginner related Bitcoin coding stuff check out this mega-thread at bitcointalk https://bitcointalk.org/index.php?topic=990348.0  It's mostly PHP and JavaScript examples.

> **Comments:**
> **username_0**: I'll test it now, thank you very much man !!  
> **username_0**: Yep, I suppose I can work with this, thanks buddy.  

---

