Skip to content

Instantly share code, notes, and snippets.

@joshmh
Created August 6, 2012 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshmh/3277395 to your computer and use it in GitHub Desktop.
Save joshmh/3277395 to your computer and use it in GitHub Desktop.
Bitcoin Price
<?php
function btc_price($price_in_usd) {
$url = 'https://mtgox.com/api/0/data/ticker.php?Currency=usd';
$response = http_parse_message(http_get($url))->body;
$obj = json_decode($response, true);
$last = $obj['ticker']['last'];
return number_format( ($price_in_usd / $last), 2 ) . " BTC";
}
echo btc_price(25.50);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment