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 API.

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

View Live Demo Of Currency Converter PHP Script

You Can Download the PHP Currency Conversion Script From here

GitHub Link

Direct Download Link

How to create free currency converter PHP Script Using Fixer API

At first, go to
Create an account there to get The API key.
For now, you will get 1000 SMS/ month for your free account. If you want to increase the number of SMS you can choose their premium plans.
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,

And the JSON File looks like this,

    ----------  //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


$api="your api key here";   ///// Provide your api key here

$string = file_get_contents("$api&format=1");
  $json = json_decode($string, true);
  foreach ($json['rates'] as $key => $value) {
$api="your api key here";

Put your API key of fixer here.

 $string = file_get_contents("$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)




$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

Now come to our main index.php file

PHP code of currency conversion


<!DOCTYPE html>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style type="text/css">
    background-color: lavender;
    text-align: center;
    margin-top: 120px;
  footer {
    font-size: 12px;
    margin: 0 auto;
    max-width: 1200px;
    position: relative;
    width: 95%;

  <title>Currency Converter</title>
  <h1>Currency Converter Using API</h1>
  <form method="post">
    Enter Amount:
    <input type="text" name="amount" value="1"><br><br>
    <select name="from">
          echo "<option value=\"$i\">$currency[$i]</option>";

      TO: <select name="to">
          echo "<option value=\"$i\">$currency[$i]</option>";

    <input type="submit" name="submit" value="Convert!">
  if (isset($_POST['amount'])) {
    $combine= array_combine($currency, $rate);
  echo " Conversion Result: <br><br> $amount $currency[$from] = "."$output $currency[$to]";

  echo "<br><br>Reverse Result:<br><br>$amount $currency[$to] = "."$reverse $currency[$from]";





Leave a Reply

Your email address will not be published. Required fields are marked *