Currency Converter in PHP

By CampCodes Administrator

Updated on:

currency converter in php

In this tutorial, we will create a Basic Money Converter using PHP. This code will convert the given value to a specific currency value. The system uses a PHP POST to save the given value base on the currency options by doing the arithmetic formulas. This is a user-friendly kind of program feel free to modify it.

We will be using PHP as a scripting language and interpreter that is mainly used on any web server, including xamp, wamp, etc. It is being used to any popular websites, and it has a modern technology that can easily be used by the next generation.

Getting Started:

First, you have to download & install XAMPP or any local server that runs PHP scripts. Here’s the link for the XAMPP server https://www.apachefriends.org/index.html.

And, this is the link for the bootstrap that I used for the layout design https://getbootstrap.com/.

Creating The Interface

This is where we will create a simple form for our application. To create a copy of the form and write it into your text editor, then save it as index.php.

<!DOCTYPE html>
<html lang="en">
    <head>
        <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
        <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
    </head>
<body>
    <nav class="navbar navbar-default">
        <div class="container-fluid">
            <a class="navbar-brand" href="https://sourcecodester.com">Sourcecodster</a>
        </div>
    </nav>
    <div class="col-md-3"></div>
    <div class="col-md-6 well">
        <h3 class="text-primary">PHP - Basic Money Converter</h3>
        <hr style="border-top:1px dotted #000;"/>
        <div class="col-md-3"></div>
        <div class="col-md-6">
            <form method="POST" action="">
                <div class="form-inline">
                    <select name="val" class="form-control">
                        <option value="PHP">PHP</option>
                        <option value="USD">USD</option>
                    </select>
                    <input class="form-control" type="number" name="digit"/>
                </div>	
                <br />
                <div class="form-inline">
                    <label>Select Currency: </label>
                    <select name="currency" required="required" class="form-control">
                        <option value="">Select an option</option>
                        <option value="USD">USD</option>
                        <option value="Euro">Euro</option>
                        <option value="PHP">PHP</option>
                        <option value="Japanese Yen">Japanese Yen</option>
                    </select>
                    <br /><br />
                    <center><button type="submit" name="convert" class="btn btn-primary form-control" style="width:30%;">Convert</button></center>
                    <br />
                </div>	
                    <?php require 'convert.php'?>
            </form>
        </div>
    </div>
</body>
</html>

Creating the Main Function

This code contains the main function of the application. This code will convert the money value when the button is clicked. To make this just copy and write these block of codes below inside the text editor, then save it as convert.php

<?php
    if(ISSET($_POST['convert'])){
        $val = $_POST['val'];
        $digit = $_POST['digit'];
        $currency = $_POST['currency'];
 
 
        if($val=="PHP" && $currency=="USD"){
            $output = $digit * 51.52;
            echo"<center><label class='text-success' style='font-size:25px;'>$".$output."</label></center>";
        }else if($val=="PHP" && $currency=="Euro"){
            $output = $digit * 63.62;
            echo"<center><label class='text-success' style='font-size:25px;'>€".$output."</label></center>";
        }else if($val=="PHP" && $currency=="PHP"){
            $output = $digit;
            echo"<center><label class='text-success' style='font-size:25px;'>₱".$output."</label></center>";
        }else if($val=="PHP" && $currency=="Japanese Yen"){
            $output = $digit * 0.47;
            echo"<center><label class='text-success' style='font-size:25px;'>¥".$output."</label></center>";
        }else if($val=="USD" && $currency=="USD"){
            $output = $digit;
            echo"<center><label class='text-success' style='font-size:25px;'>$".$output."</label></center>";
        }else if($val=="USD" && $currency=="Euro"){
            $output = $digit*0.89;
            echo"<center><label class='text-success' style='font-size:25px;'>€".$output."</label></center>";
        }else if($val=="USD" && $currency=="PHP"){
            $output = $digit/51.52;
            echo"<center><label class='text-success' style='font-size:25px;'>₱".$output."</label></center>";
        }else if($val=="USD" && $currency=="Japanese Yen"){
            $output = $digit*107.72;
            echo"<center><label class='text-success' style='font-size:25px;'>¥".$output."</label></center>";
        }
    }
?>

Next Step for Your Project Journey

Pick your next action to keep building: download complete source code, continue with practical tutorials, or explore more project systems.

Explore Source Code Continue Tutorials Final Year Projects
basic money converter in php best currency converter api currency api for android currency api free currency api google currency conversion api currency conversion api google currency conversion web service currency conversion web service example currency converter api currency converter api android currency converter api for ios currency converter api free currency converter api google currency converter api java currency converter api magento 2 currency converter in php currency converter in php demo currency converter in php source code currency converter php script currency converter python package currency converter script currency converter using php currency converter web service currency converter web service in java currency exchange api currency exchange api google currency exchange rate api currency exchange rate api google currency exchange xml exchange rate api exchange rate api google exchange rate rss feed google exchange rates api forex historical data api free automatic currency converter for website free currency api free currency conversion api free currency converter api free currency exchange free currency exchange rate api free currency feed free exchange rate api google api currency conversion rates google currency api google currency converter api google currency converter api json google finance currency converter api historical forex data api layer currency live currency converter in php open exchange rates api open exchange rates app php exchange rate api php tutorials python currency converter github real time currency rates api free xe api documentation xe api free xe data yahoo exchange rate api

4 thoughts on “Currency Converter in PHP”

Leave a Comment