USD to bitcoin, bitcoin exchange rate – Php code

Convert USD to bitcoin or get the latest value of bitcoin. The easiest way to get the bitcoin exchange rate

<?php
$amount=100;
$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_URL => "https://blockchain.info/tobtc?currency=USD&value=" . $amount,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => array(
        "cache-control: no-cache",
        "postman-token: fc62ebce-6d0b-ef4f-ba02-fcb05e284a02"
    ),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
echo $amount = json_decode($response);
?>

Above is programmatic code that you can use in your server but if you want to see in the browser then just do

https://blockchain.info/tobtc?currency=USD&value=100

Parameters
  • currency – A currency code. See the list above.
  • value – Value to convert.

Returns the value in BTC.

Previous articleHow to redirect Add to Cart button in opencart to the cart page directly
Next articleUncaught exception ‘Exception’ with message ‘Error: Could not load model payment!’ in vqmod\vqcache\vq2-system_engine_loader.php
Author of three Opencart book. The recent Opencart 4 book is at https://amzn.to/4dOlbOR

2 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here