Location: PHPKode > scripts > CurrencyExchange > currencyexchange/example2.php
<?php
$from = "";
$to = "";
$result = "";
$amount = "";

if (isset($_POST['from']) && isset($_POST['to'])){
    
    $from = addslashes($_POST['from']);
    $to = addslashes($_POST['to']);
    $amount = addslashes($_POST['amount']);

    include("CurrencyConverter.php");

    $exch = new CurrencyConverter();
    $exch->fromTo($from, $to);
    $val = $exch->convertAmount($amount);

    if (!$val){
        $result = "Couldn't convert due to some internal error.<br />" . nl2br($exch->getError()) . nl2br($exch->getDebug());
    } else {
        $result = number_format($val, 2, '.', ',');
        $amount = number_format($amount, 2, '.', ',');;
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en">
<head>
<style type="text/css">
body{
   background: #f1f1f1;
   margin: 1% auto; 
   width: 95%;
   font: 0.75em/1.4 Geneva, Arial, Helvetica, sans-serif;
   color: #362F2D;
}
</style>
<title>Currency convertor</title>
</head>
<body>
<form name="form1" method="POST">
Convert amount:<br />
<input type="text" name="amount" value="1.0" /><br /><br />
From:<br />
<select name="from">
<option value="EUR">Euro</option>
<option value="USD">US dollar</option>
<option value="JPY">Japanese yen</option>
<option value="CYP">Cyprus pound</option>
<option value="CZK">Czech koruna</option>
<option value="DKK">Danish krone</option>
<option value="EEK">Estonian kroon</option>
<option value="GBP">Pound sterling</option>
<option value="HUF">Hungarian forint</option>
<option value="LTL">Lithuanian litas</option>
<option value="LVL">Latvian lats</option>
<option value="MTL">Maltese lira</option>
<option value="PLN">Polish zloty</option>
<option value="SEK">Swedish krona</option>
<option value="SIT">Slovenian tolar</option>
<option value="SKK">Slovak koruna</option>
<option value="CHF">Swiss franc</option>
<option value="ISK">Icelandic krona</option>
<option value="NOK">    Norwegian krone</option>
<option value="BGN">Bulgarian lev</option>
<option value="HRK">Croatian kuna</option>
<option value="RON">New Romanian leu</option>
<option value="RUB">Russian rouble</option>
<option value="TRY">New Turkish lira</option>
<option value="AUD">Australian dollar</option>
<option value="CAD">Canadian dollar</option>
<option value="CNY">Chinese yuan renminbi</option>
<option value="HKD">Hong Kong dollar</option>
<option value="IDR">Indonesian rupiah</option>
<option value="KRW">South Korean won</option>
<option value="MYR">Malaysian ringgit</option>
<option value="NZD">New Zealand dollar</option>
<option value="PHP">    Philippine peso</option>
<option value="SGD">Singapore dollar</option>
<option value="THB">Thai baht</option>
<option value="ZAR">South African rand</option>
</select>
<br /><br />
To:<br />
<select name="to">
<option value="EUR">Euro</option>
<option value="USD">US dollar</option>
<option value="JPY">Japanese yen</option>
<option value="CYP">Cyprus pound</option>
<option value="CZK">Czech koruna</option>
<option value="DKK">Danish krone</option>
<option value="EEK">Estonian kroon</option>
<option value="GBP">Pound sterling</option>
<option value="HUF">Hungarian forint</option>
<option value="LTL">Lithuanian litas</option>
<option value="LVL">Latvian lats</option>
<option value="MTL">Maltese lira</option>
<option value="PLN">Polish zloty</option>
<option value="SEK">Swedish krona</option>
<option value="SIT">Slovenian tolar</option>
<option value="SKK">Slovak koruna</option>
<option value="CHF">Swiss franc</option>
<option value="ISK">Icelandic krona</option>
<option value="NOK">    Norwegian krone</option>
<option value="BGN">Bulgarian lev</option>
<option value="HRK">Croatian kuna</option>
<option value="RON">New Romanian leu</option>
<option value="RUB">Russian rouble</option>
<option value="TRY">New Turkish lira</option>
<option value="AUD">Australian dollar</option>
<option value="CAD">Canadian dollar</option>
<option value="CNY">Chinese yuan renminbi</option>
<option value="HKD">Hong Kong dollar</option>
<option value="IDR">Indonesian rupiah</option>
<option value="KRW">South Korean won</option>
<option value="MYR">Malaysian ringgit</option>
<option value="NZD">New Zealand dollar</option>
<option value="PHP">    Philippine peso</option>
<option value="SGD">Singapore dollar</option>
<option value="THB">Thai baht</option>
<option value="ZAR">South African rand</option>
</select>
<input type="submit" name="submit" value="Submit" />
</form>
<?php
if ($result != ""){
echo "<h3>Result: $amount $from = $result $to</h3>";
}
?>

<div style="margin: 1em;border: 1px solid #ccc;background: #fff;padding: 1em">
<?php
if (is_object($exch)){

    $err = $exch->getError();
    if ($err != ""){
        echo "<h3>Errors:</h3>".$err."<br />";
    }
    
    $debug = $exch->getDebug();
    if ($debug != ""){
        echo "<h3>Debug:</h3>".$debug."<br />";
    }
    
}
?>
</div>

<a href="http://www.ecreate.co.uk">Code by eCreate.</a>
</body>
</html>
Return current item: CurrencyExchange