The Dude man
The Dude man

Reputation: 413

PHP Variable to Blockchain ToBTC API

I am having trouble getting the Blockchain ToBTC API to return the value of a PHP variable.

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

$total_price+=$price;

$btc_total = echo "https://blockchain.info/tobtc?currency=USD&value=$total_price";

Is it possible to do it this way or do I need to parse with JSON? I am new to PHP, not really my thing as I care more for python. However, this is a PHP project. Thank you for reading, any help is appreciated.

Upvotes: 0

Views: 246

Answers (1)

Niklesh Raut
Niklesh Raut

Reputation: 34924

First, you have syntax error in your code use this line to print url,

echo $btc_total = "https://blockchain.info/tobtc?currency=USD&value=$total_price";

You should use curl to get value from above url.

<?php
    $total_price += $price;
    $curl = curl_init('https://blockchain.info/tobtc?currency=USD&value='.$total_price);
    curl_setopt($curl, CURLOPT_FAILONERROR, true);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    $result = curl_exec($curl);
    echo $result;
?>

Upvotes: 1

Related Questions