Free Currency Converter PHP using Fixer io API

By Saruque Ahamed Mollick

Hello, Today I am gonna provide you Currency Converter API  PHP Source Code with explanation and how to use that PHP Script.

This tutorial will help you to create your own PHP Currency Converter Script using Fixer.io API.

Also read,

Real Time Chat Application PHP With File Transfer System  AJAX



Features of this PHP Script :

  1. You can convert one currency into another.
  2. You will have all the currency in a  list as a drop-down menu. ( All the drop-down options are being fetched from the API JSON Data)
  3. You will get the conversion result of currency exchange as well as the Reverse currency exchange result.
  4. Easy to use and easy to understand.
  5. Optimized Code and Light Weight.

You can see the live demo of this PHP Script from Here
Due to some strong reason, we are not providing the script for free anymore.
We strongly recommend you to purchase the product from the given link below

Purchase it

 

Pro Version Of this Currency converter PHP Script

In pro version, you don’t need to click on any convert or submit button. Just enter the amount and the currency will be converted instantly without hitting extra API usage again and again.

Live demo Of PRO Currency Converter

Buy PRO Version

To get custom design and style or modification Contact Us

 

How to create free currency converter PHP Script Using Fixer API

At first, go to https://fixer.io
Create an account there to get The API key.

But I will suggest you create a free account first to test your script.

After creating an account you will get a unique API key.

Now here your Coding Starts.
At first, you need to create a PHP file to fetch all the data from Fixer JSON file.

The JSON file URL looks like this,

http://data.fixer.io/api/latest?access_key=API_KEY_HERE&format=1

And the JSON File looks like this,

{
  "success":true,
  "timestamp":1534049006,
  "base":"EUR",
  "date":"2018-08-12",
  "rates":{
    "AED":4.195718,
    "AFN":82.71609,
    "ALL":125.647934,
    "AMD":550.747778,
    "ANG":2.107342,
    "AOA":296.657252,
    "ARS":33.354893,
    "AUD":1.564088,
    "AWG":2.047769,
    "AZN":1.944686,
    "BAM":1.948851,
    "BBD":2.286099,
    "BDT":96.512186,
    "BGN":1.957936,
    "BHD":0.431017,
    "BIF":2040.058712,
    ----------
    ----------  //more data
    ----------
    ----------
}
}

If you have the API key then you can get this JSON file URL easily by accessing that URL.
The URL will also be provided in Fixer account.

You might also be interested in,

Find Out What Happened On This Day PHP Script Using Hiztory API

Movie Video Trailers And Info PHP Script That Uses TMDB API

Get the distance between two places in PHP with Google Map API

Create a PHP file to fetch all the currency rate and data from JSON File

This is your PHP file to fetch all the currency data

<?php


$api="your api key here";   ///// Provide your fixer.io api key here


$string = file_get_contents("http://data.fixer.io/api/latest?access_key=$api&format=1");
  $json = json_decode($string, true);
  
  
  $i=0;
  foreach ($json['rates'] as $key => $value) {
    $currency[$i]=$key;
    $rate[$i]=$value;
    $i=$i+1;
        
  }
  
?>
$api="your api key here";

Put your API key of fixer here.

 $string = file_get_contents("http://data.fixer.io/api/latest?access_key=$api&format=1");

Thereafter, You have to use file_get_contents function to read the contents of the JSON file into a string.

Then, json_decode is used to convert the data into an object.

So now you carefully look at the JSON file structure. We have currency names and their value. SO we can use those as array.

 foreach ($json['rates'] as $key => $value)

 { 

$currency[$i]=$key; 

$rate[$i]=$value; 

$i=$i+1; }

By this foreach loop, we can easily store all the currency names and their value in array variable.

$currency[] array is used to store the currency names and $rate[] array is used to store their rates. (our base currency is EUR here)

As we have used array so it is cleared that $currency[5] will be the currency name of 6th currency listed in our JSON file. (as index starts with zero)

PHP Weather Forecast Script That Uses OpenWeatherMap API