[thelist] New to PHP - Code for calculations

Paul Bennett paul at teltest.com
Mon Aug 11 16:40:26 CDT 2003


Ken Wan wrote:

>Please help a PHP newbie. I don't have time to learn PHP but need to create
>a currency converter. I'd like to keep the calculation separate from the
>conversion rate, so that someone who is not web-savvy at all can go and edit
>the conversion value (variable in a file called conversion.php for example)
>and have it updated globally on a website. Only one conversion is required
>(i.e. from Canadian dollars to American).
>
>What would I need to do?
>
>Thanks
>Ken
>  
>
assuming you are going to be GETting / POSTing the data to be converted
(yes, I am working on a pre php 4.1.0 server, so others may use $_POST 
instead of $HTTP_POST_VARS)
<?
# get conversion variable(s)
require_once('conversion.php');

# check some data exists in the post field
if(strlen ( trim ( $HTTP_POST_VARS['currency'])) > 0 )
    {
    # you would need checks for numeric format here
    # assuming data is numeric
    # '*' is the multiplier operator in php
    # $canadianExchangeRate is the exchage from USD to canadian
    $dollarOutput = $HTTP_POST_VARS['currency'] * $canadianExchangeRate;
    echo $HTTP_POST_VARS['currency'].' of USD will get you 
'.$dollarOutput.' canadian dollars';
    }
else
    {
    echo 'Fool! You posted no currency!'
    }
?>

-- 
 ------------------------------
	Paul Bennett						
	Internet Developer				
	Teltest Electronic Design		
 ------------------------------			
Email: paul at teltest.com				
Phone: 64 4 237 4557					
Web: http://www.teltest.com		
Wap: http://wap.teltest.com			




More information about the thelist mailing list