Currency Converter
The code for the currency converter on Valhalla's Tools page.
<?php /* * Author: ynori7 * Copyright: halls-of-valhalla.org */ //rates from X to USD $rates = array(); $rates['Argentine Peso'] = 4.42411; $rates['Australian Dollar'] = 0.947301; $rates['Botswana Pula'] = 6.78887; $rates['Brazilian Real'] = 1.64615; $rates['British Pound'] = 0.622101; $rates['Brunei dollar'] = 1.2086; $rates['Bulgarian Lev'] = 1.38719; $rates['Canadian Dollar'] = 0.992411; $rates['Chilean Peso'] = 463.951; $rates['Chinese Yuan'] = 6.39052; $rates['Colombian Peso'] = 1792.04; $rates['Croatian Kuna'] = 5.31031; $rates['Danish Krone'] = 5.2835; $rates['Euro'] = 0.70927; $rates['Hong Kong Dollar'] = 7.79382; $rates['Hungarian Forint'] = 196.631; $rates['Iceland Krona'] = 116.233; $rates['Indian Rupee'] = 45.9848; $rates['Indonesian Rupiah'] = 8559.17; $rates['Iranian Rial'] = 10616; $rates['Israeli New Shekel'] = 3.66934; $rates['Japanese Yen'] = 77.3743; $rates['Kazakhstani Tenge'] = 146.8; $rates['Kuwaiti Dinar'] = 0.2733; $rates['Latvian Lat'] = 0.503085; $rates['Libyan Dinar'] = 1.9324; $rates['Lithuanian Litas'] = 2.44897; $rates['Malaysian Ringgit'] = 2.98298; $rates['Mauritius Rupee'] = 28.1745; $rates['Mexican Peso'] = 12.537; $rates['Nepalese Rupee'] = 73.45; $rates['New Zealand Dollar'] = 1.20377; $rates['Norwegian Kroner'] = 5.38797; $rates['Omani Rial'] = 0.3845; $rates['Pakistan Rupee'] = 87.4669; $rates['Philippine Peso'] = 42.3179; $rates['Qatari Rial'] = 3.64; $rates['Romanian Leu'] = 3.01724; $rates['Russian Ruble'] = 29.5807; $rates['Saudi Riyal'] = 3.75; $rates['Singapore Dollar'] = 1.20838; $rates['South African Rand'] = 7.13398; $rates['South Korean Won'] = 1074.46; $rates['Sri Lanka Rupee'] = 109.964; $rates['Swedish Krona'] = 6.44641; $rates['Swiss Franc'] = 0.853678; $rates['Taiwan Dollar'] = 29.1043; $rates['Thai Baht'] = 29.9149; $rates['Trinidad/Tobago Dollar'] = 6.38943; $rates['Turkish Lira'] = 1.76998; $rates['US Dollar'] = 1; //this is the default because i had to pick something $rates['Venezuelan Bolivar'] = 4.29376; if(isset($_POST['amount']) and isset($_POST['currency1']) and isset($_POST['currency2'])) { $amount = number_format((double) $_POST['amount'], 2); $c1 = $_POST['currency1']; $c2 = $_POST['currency2']; if($amount<=0 or !isset($rates[$c1]) or !isset($rates[$c2])) { echo "<p>Invalid input.</p><br/>\n"; } else{ $result = number_format($amount/$rates[$c1], 2); //to dollars $result = number_format($result*$rates[$c2], 2); //to new currency echo "Result = $result $c2(s)."; } } echo "<p>Note: Exchange rates last updated September 6th, 2011.</p> <form action='' method='POST'> <table> <tr> <td>Amount To Convert:</td> <td><input type='text' name='amount' maxlength='50'></td> </tr> <tr> <td><u>From:</u></td> <td style='padding-left:50px'><u>To:</u></td> </tr> <tr> <td>"; foreach(array_keys($rates) as $currency) echo "<input type='radio' name='currency1' value='$currency'>$currency<br/>\n"; echo "</td> <td style='padding-left:50px'>"; foreach(array_keys($rates) as $currency) echo "<input type='radio' name='currency2' value='$currency'>$currency<br/>\n"; echo "</td> </tr> <tr> <td colspan='4'><center><input type='submit' value='submit'></center></td> </tr> </table> </form>\n"; ?>

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Download this code in plain text format here