Click
for a preview of what you are going to learn and how the result looks like.I'm fully aware that this is not rocket-science but this is more of a "noobtorial", targeted towards those who would love to learn PHP and JSON-integration.
First step you wanna do is create a PHP document.
Code:
<?php ?>
Code:
<?php $api = "https://blockchain.info/de/ticker"; ?>
Code:
<?php $api = "https://blockchain.info/de/ticker"; $json = file_get_contents($api); ?>
This is how you should proceed:
(Ignore the TRUE for now, this is necessary due to the nature of arrays.)
Code:
<?php $api = "https://blockchain.info/de/ticker"; $json = file_get_contents($api); $data = json_decode($json, TRUE); ?>
for the actual JSON-stream that shows a list of possible currency abbreviations. The '15min' stands for the average Bitcoin price in the last 15 minutes, you might also take the sell/buy price. Other Bitcoin APIs may vary from this. The usage for the data extraction should be clear from the example.Code:
<?php $api = "https://blockchain.info/de/ticker"; $json = file_get_contents($api); $data = json_decode($json, TRUE); $rate = $data["EUR"]["15m"]; ?>
Code:
<?php $api = "https://blockchain.info/de/ticker"; $json = file_get_contents($api); $data = json_decode($json, TRUE); $rate = $data["EUR"]["15m"]; $symbol = $data["EUR"]["symbol"]; ?>
Code:
<?php $api = "https://blockchain.info/de/ticker"; $json = file_get_contents($api); $data = json_decode($json, TRUE); $rate = $data["EUR"]["15m"]; $symbol = $data["EUR"]["symbol"]; echo "1 Bitcoin equals " . $rate . $symbol; ?>
What I've done to make it a tiny bit more user-friendly is to set the font to Verdana. This isn't necessary but you get the point.
Below is the full code:
Code:
<?php $api = "https://blockchain.info/de/ticker"; $json = file_get_contents($api); $data = json_decode($json, TRUE); $rate = $data["EUR"]["15m"]; $symbol = $data["EUR"]["symbol"]; echo "<div style='font-family:verdana,arial,sans-serif'> 1 Bitcoin equals " . $rate . $symbol . "</div>"; ?>






