Bitcoin Forum

Bitcoin => Project Development => Topic started by: Th0ur007 on May 07, 2016, 01:33:28 PM



Title: [GUIDE] How to Make Bitcoin Price Converter in 2 Mins! [HTML/PHP]
Post by: Th0ur007 on May 07, 2016, 01:33:28 PM
Added Guide for Altcoin Conversion (https://bitcointalk.org/index.php?topic=1466793.new#new)

Introduction:
Hello All, Today i am going to tell you how to make your own currency converter using PHP and HTML. I know it seems to be difficult but when you understand it properly, it becomes a small piece of work for you. I will simply use https://bitcoinaverage.com/api to make it work. Let's Go.

Steps to Follow:
Kindly follow all the steps and read carefully to understand the meaning of each and every word, so it would be easier to do it yourself.

Step 1 - A Basic HTML Page:
First of all, You should create a basic HTML Page like this in any of your text editor:
Code:
<html>
<head>
<title>Bitcoin Price Converter</title>
</head>

<body>
</body>

</html>

Step 2 - PHP Script:
Now we will put PHP Coding to grab data using API. If you are not aware what is an API, Check this video: What is an API? (https://www.youtube.com/watch?v=s7wmiS2mSXY)
Let's start with creating a variable "$url". This variable will be used to grab data from the API Link i.e. https://api.bitcoinaverage.com/ticker/global/USD/
Code:
<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/USD/";
?>

Once we get our data from the API, We will have to decode it using JSON. Create a variable called $price in which we will store our decoded information.
Code:
<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/USD/";
$price json_decode(file_get_contents($url), true);
?>

At this moment we have the API's Information in the variable called $price, It's time to get an exact data which we want i.e. last price. We will create a new variable called $last_price and will store the price in it.
Code:
<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/USD/";
$price json_decode(file_get_contents($url), true);
$last_price $price['last'];
?>

You did it, we got all the data and it's time to show it. Simply use echo function of PHP to output the data:
Code:
<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/USD/";
$price json_decode(file_get_contents($url), true);
$last_price $price['last'];
echo 
"$last_price";
?>

Step 3 - Integrate HTML with PHP:
Now put the PHP Code on the top of the HTML Page we created before like this:
Code:
<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/USD/";
$price json_decode(file_get_contents($url), true);
$last_price $price['last'];
echo 
"$last_price";
?>


<html>
<head>
<title>Bitcoin Price Converter</title>
</head>

<body>
</body>

</html>

Step 4 - Auto Refresh Page (credit goes to KenR to remind me about this)
Our Converter is ready, we are going to add an auto refresh code to make it display the latest values. Simply add this code:
Code:
<meta content='10' http-equiv='refresh'/> <!-- Reloads Page every 10 seconds -->

FINAL:
That's what we get!
Code:
<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/USD/";
$price json_decode(file_get_contents($url), true);
$last_price $price['last'];
echo 
"$last_price";
?>


<html>
<head>
<title>Bitcoin Price Converter</title>
<meta content='10' http-equiv='refresh'/> <!-- Reloads Page every 10 seconds -->
</head>

<body>
</body>

</html>

Tada! You did it ;)



Hope this Guide helped you in understanding the concept of API's, Drop me some comments to motivate :)
If you want to Donate, Please: 18L6tGTdJfCenGxzc8ZDLsjBNaUfekXzjj


Title: Re: [GUIDE] How to Make Bitcoin Price Converter in 2 Mins! [HTML/PHP]
Post by: locopao on May 07, 2016, 04:01:30 PM
Thanks a lot for the real nice guide!

so if someone wants to show the price for different currencies, should do something like this?

Code:
<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/USD/";
$price json_decode(file_get_contents($url), true);
$last_price $price['last'];?>


<?php echo "$last_price";
?>


<br>

<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/EUR/";
$price json_decode(file_get_contents($url), true);
$last_price $price['last'];?>


<?php echo "$last_price";
?>


<br>

<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/GBP/";
$price json_decode(file_get_contents($url), true);
$last_price $price['last'];?>


<?php echo "$last_price";
?>


<br>

<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/JPY/";
$price json_decode(file_get_contents($url), true);
$last_price $price['last'];?>


<?php echo "$last_price";
?>


<br>

<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/RUB/";
$price json_decode(file_get_contents($url), true);
$last_price $price['last'];?>


<?php echo "$last_price";
?>

and maybe add some css to format the output?
(was never good in php  :P)


Title: Re: [GUIDE] How to Make Bitcoin Price Converter in 2 Mins! [HTML/PHP]
Post by: radhwane on May 07, 2016, 04:38:58 PM
Thank you very much for this guide really it help me a lot
Its possible to make a bitcoin price like preev.com ?
For example I writ 0.0153 in bitcoin and i see the result in USD ?
Thanks again


Title: Re: [GUIDE] How to Make Bitcoin Price Converter in 2 Mins! [HTML/PHP]
Post by: Th0ur007 on May 07, 2016, 04:54:01 PM
Thanks a lot for the real nice guide!

so if someone wants to show the price for different currencies, should do something like this?

Code:
<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/USD/";
$price json_decode(file_get_contents($url), true);
$last_price $price['last'];?>


<?php echo "$last_price";
?>


<br>

<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/EUR/";
$price json_decode(file_get_contents($url), true);
$last_price $price['last'];?>


<?php echo "$last_price";
?>


<br>

<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/GBP/";
$price json_decode(file_get_contents($url), true);
$last_price $price['last'];?>


<?php echo "$last_price";
?>


<br>

<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/JPY/";
$price json_decode(file_get_contents($url), true);
$last_price $price['last'];?>


<?php echo "$last_price";
?>


<br>

<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/RUB/";
$price json_decode(file_get_contents($url), true);
$last_price $price['last'];?>


<?php echo "$last_price";
?>

and maybe add some css to format the output?
(was never good in php  :P)
Yup, Thats the way to add the other currency support.
Thank you for your comment.


Title: Re: [GUIDE] How to Make Bitcoin Price Converter in 2 Mins! [HTML/PHP]
Post by: Th0ur007 on May 07, 2016, 04:56:54 PM
Thank you very much for this guide really it help me a lot
Its possible to make a bitcoin price like preev.com ?
For example I writ 0.0153 in bitcoin and i see the result in USD ?
Thanks again
Yup, Here are some steps how it will go:
- Get Current 1 BTC Rate
- Multiply Current BTC Rate with your value 'X'

In your case:
0.0153*458=7.021

Cheers.


Title: Re: [GUIDE] How to Make Bitcoin Price Converter in 2 Mins! [HTML/PHP]
Post by: socks435 on May 07, 2016, 05:03:04 PM
Very nice guide for me and it help to to put it in my site..
Also i want to use this for reference to make a converter for other altcoin.. i hope i can make mine with CBX price converter..
I am looking for other codes to increase my knowledge for making a new site which exchange site.. thanks again for this guide..


Title: Re: [GUIDE] How to Make Bitcoin Price Converter in 2 Mins! [HTML/PHP]
Post by: Th0ur007 on May 07, 2016, 05:06:48 PM
Very nice guide for me and it help to to put it in my site..
Also i want to use this for reference to make a converter for other altcoin.. i hope i can make mine with CBX price converter..
I am looking for other codes to increase my knowledge for making a new site which exchange site.. thanks again for this guide..
Your welcome mate, You can use any API to make one for any altcoin.
Simply change the URL of API and other is same.

I will PM you an example of CBX once im free.
Cheers.

EDIT:
CBX-USD:
Code:
<?php 
$url 
"https://www.cryptonator.com/api/ticker/cbx-usd";
$data json_decode(file_get_contents($url), true);
$ticker $data['ticker'];
$latest_price $ticker['price'];
echo 
"$latest_price";
?>


<html>
<head>
<title>CBX Price Converter</title>
</head>

<body>
</body>

</html>


Title: Re: [GUIDE] How to Make Bitcoin Price Converter in 2 Mins! [HTML/PHP]
Post by: socks435 on May 07, 2016, 05:38:47 PM
Very nice guide for me and it help to to put it in my site..
Also i want to use this for reference to make a converter for other altcoin.. i hope i can make mine with CBX price converter..
I am looking for other codes to increase my knowledge for making a new site which exchange site.. thanks again for this guide..
Your welcome mate, You can use any API to make one for any altcoin.
Simply change the URL of API and other is same.

I will PM you an example of CBX once im free.
Cheers.

EDIT:
CBX-USD:
Code:
<?php 
$url 
"https://www.cryptonator.com/api/ticker/cbx-usd";
$data json_decode(file_get_contents($url), true);
$ticker $data['ticker'];
$latest_price $ticker['price'];
echo 
"$latest_price";
?>


<html>
<head>
<title>CBX Price Converter</title>
</head>

<body>
</body>

</html>
Wow great i will try it in free domain and hosting and i hope it will work..
And i hope i can see the sample once you are free,, thanks


Title: Re: [GUIDE] How to Make Bitcoin Price Converter in 2 Mins! [HTML/PHP]
Post by: KenR on May 07, 2016, 05:51:39 PM
That is a very easy one.You can simply get in down with lot of other API's.Problem here is what is the refresh rate in seconds ? How often the page reloads to display the latest values ? I don't see any code for that.


Title: Re: [GUIDE] How to Make Bitcoin Price Converter in 2 Mins! [HTML/PHP]
Post by: Th0ur007 on May 07, 2016, 05:57:06 PM
That is a very easy one.You can simply get in down with lot of other API's.Problem here is what is the refresh rate in seconds ? How often the page reloads to display the latest values ? I don't see any code for that.
Thank you for your comment. It was just a simple script to use API to convert price.
To refresh the page after every 10 seconds, add this line in <head>:
Code:
<meta content='10' http-equiv='refresh'/>

It becomes:
Code:
<?php 
$url 
"https://api.bitcoinaverage.com/ticker/global/USD/";
$price json_decode(file_get_contents($url), true);
$last_price $price['last'];
echo 
"$last_price";
?>


<html>
<head>
<title>Bitcoin Price Converter</title>
<meta content='10' http-equiv='refresh'/> <!-- Reloads Page every 10 seconds -->
</head>

<body>
</body>

</html>


Title: Re: [GUIDE] How to Make Bitcoin Price Converter in 2 Mins! [HTML/PHP]
Post by: KenR on May 07, 2016, 06:00:53 PM
Thank you for your comment. It was just a simple script to use API to convert price.
To refresh the page after every 10 seconds, add this line in <head>:

Better now.Might as well want to update that in the main post as this is a must if someone will be using the code. :)


Title: Re: [GUIDE] How to Make Bitcoin Price Converter in 2 Mins! [HTML/PHP]
Post by: Th0ur007 on May 07, 2016, 06:01:21 PM
Thank you for your comment. It was just a simple script to use API to convert price.
To refresh the page after every 10 seconds, add this line in <head>:

Better now.Might as well want to update that in the main post as this is a must if someone will be using the code. :)
Already did, Thank you for your suggestion. :)


Title: Re: [GUIDE] How to Make Bitcoin Price Converter in 2 Mins! [HTML/PHP]
Post by: lixer on May 07, 2016, 06:27:45 PM
I appreciate the guide and I'm pretty sure I'm not the only one.
I bookmarked it and copy-pasted the content to a document just in case because I just don't think this is in the right section.


Title: Re: [GUIDE] How to Make Bitcoin Price Converter in 2 Mins! [HTML/PHP]
Post by: lofty on May 07, 2016, 06:46:42 PM
This is nice ! I was bored so I made this using JQuery :) Hope OP won't mind me sharing that.

https://jsfiddle.net/aveavaeva/kttyh4d2/


Title: Re: [GUIDE] How to Make Bitcoin Price Converter in 2 Mins! [HTML/PHP]
Post by: Th0ur007 on May 07, 2016, 06:54:34 PM
I appreciate the guide and I'm pretty sure I'm not the only one.
I bookmarked it and copy-pasted the content to a document just in case because I just don't think this is in the right section.
Thank you for the comment, Mod will move it to perfect place if he wants to :)



Title: Re: [GUIDE] How to Make Bitcoin Price Converter in 2 Mins! [HTML/PHP]
Post by: Th0ur007 on May 07, 2016, 06:56:18 PM
This is nice ! I was bored so I made this using JQuery :) Hope OP won't mind me sharing that.

https://jsfiddle.net/aveavaeva/kttyh4d2/
That's nice, I could do it in PHP but just wanted to make it easy to understand :)


Title: Re: [GUIDE] How to Make Bitcoin Price Converter in 2 Mins! [HTML/PHP]
Post by: mookid on May 08, 2016, 01:10:20 AM
A pretty simple and clear guide, thanks for sharing this! It would be awsome if you can make a similar guide about how to create a script to get info from an exchange via API's.


Title: Re: [GUIDE] How to Make Bitcoin Price Converter in 2 Mins! [HTML/PHP]
Post by: Th0ur007 on May 08, 2016, 05:02:35 AM
A pretty simple and clear guide, thanks for sharing this! It would be awsome if you can make a similar guide about how to create a script to get info from an exchange via API's.
Will try it, Thanks alot.


Title: Re: [GUIDE] How to Make Bitcoin Price Converter in 2 Mins! [HTML/PHP]
Post by: locopao on May 08, 2016, 12:26:41 PM
here is a screenshot of a simple use of Th0ur007's code
as a sidebar widget in a wordpress site

https://i.imgur.com/sjBP5wM.jpg

According to BitcoinAverage it's free to use their API as long as you credit them



Title: Re: [GUIDE] How to Make Bitcoin Price Converter in 2 Mins! [HTML/PHP]
Post by: Th0ur007 on May 08, 2016, 12:48:40 PM
here is a screenshot of a simple use of Th0ur007's code
as a sidebar widget in a wordpress site

https://i.imgur.com/sjBP5wM.jpg

According to BitcoinAverage it's free to use their API as long as you credit them


Looks cool :)
Cheers.


Title: Re: [GUIDE] How to Make Bitcoin Price Converter in 2 Mins! [HTML/PHP]
Post by: GregH37 on May 08, 2016, 01:05:54 PM
Seems that it is a very useful and helpful guide. I always open websites to convert my earning to other currencies, I think it would make me more compatible and safe my time.
Just bookmarked your post. I'll follow the setups latter. please inform me in PM if by chance you move this thread to somewhere else. Actually I think it belongs to help and beginner section.

Thanks again.


Title: Re: [GUIDE] How to Make Bitcoin Price Converter in 2 Mins! [HTML/PHP]
Post by: Th0ur007 on May 08, 2016, 01:15:39 PM
Seems that it is a very useful and helpful guide. I always open websites to convert my earning to other currencies, I think it would make me more compatible and safe my time.
Just bookmarked your post. I'll follow the setups latter. please inform me in PM if by chance you move this thread to somewhere else. Actually I think it belongs to help and beginner section.

Thanks again.
This thread has been moved to Project & Development by a moderator! BTW, Thanks for your comment :)
Glad it's helpful to you.


Title: Re: [GUIDE] How to Make Bitcoin Price Converter in 2 Mins! [HTML/PHP]
Post by: socks435 on May 08, 2016, 01:18:44 PM
here is a screenshot of a simple use of Th0ur007's code
as a sidebar widget in a wordpress site

https://i.imgur.com/sjBP5wM.jpg

According to BitcoinAverage it's free to use their API as long as you credit them



This one is great design.. nad i hope i can design to to my price converter.
How about sir making an api sir?


Title: Re: [GUIDE] How to Make Bitcoin Price Converter in 2 Mins! [HTML/PHP]
Post by: locopao on May 08, 2016, 02:12:59 PM
here is a screenshot of a simple use of Th0ur007's code
as a sidebar widget in a wordpress site

https://i.imgur.com/sjBP5wM.jpg

According to BitcoinAverage it's free to use their API as long as you credit them



This one is great design.. nad i hope i can design to to my price converter.
How about sir making an api sir?

It's not so hard

You just use the Th0ur007's code and then you mark up the whole thing with a div class and use awesome fonts for the currency symbols and a background image

dollar sign = http://fortawesome.github.io/Font-Awesome/icon/usd/
euro sign = http://fortawesome.github.io/Font-Awesome/icon/eur/
gpb sign = http://fortawesome.github.io/Font-Awesome/icon/gbp/
rub sign = http://fortawesome.github.io/Font-Awesome/icon/rub/
jpy sign = http://fortawesome.github.io/Font-Awesome/icon/jpy/

and so on


Title: Re: [GUIDE] How to Make Bitcoin Price Converter in 2 Mins! [HTML/PHP]
Post by: lofty on May 08, 2016, 02:40:33 PM
here is a screenshot of a simple use of Th0ur007's code
as a sidebar widget in a wordpress site

https://i.imgur.com/sjBP5wM.jpg

According to BitcoinAverage it's free to use their API as long as you credit them


This is nicely done !


Title: Re: [GUIDE] How to Make Bitcoin Price Converter in 2 Mins! [HTML/PHP]
Post by: Th0ur007 on May 08, 2016, 07:52:37 PM
here is a screenshot of a simple use of Th0ur007's code
as a sidebar widget in a wordpress site

https://i.imgur.com/sjBP5wM.jpg

According to BitcoinAverage it's free to use their API as long as you credit them


This is nicely done !
Yup, it looks cool and professional.


Title: Re: [GUIDE] How to Make Bitcoin Price Converter in 2 Mins! [HTML/PHP]
Post by: wdnj on May 09, 2016, 11:15:55 PM
 Is there similar guide for ALT dogecoin ..etc. BTW its simple and very good guide :)


Title: Re: [GUIDE] How to Make Bitcoin Price Converter in 2 Mins! [HTML/PHP]
Post by: Th0ur007 on May 09, 2016, 11:18:04 PM
Is there similar guide for ALT dogecoin ..etc. BTW its simple and very good guide :)
Thanks for the comment, I will post one for each altcoin section.
Cheers.


Title: Re: [GUIDE] How to Make Bitcoin Price Converter in 2 Mins! [HTML/PHP]
Post by: Th0ur007 on May 09, 2016, 11:27:39 PM
Added Guide for Altcoin Conversion (https://bitcointalk.org/index.php?topic=1466793.new#new)