Re: currency conversion
| From: | Robin Vickery | Date: | Thu, 15 Feb 2001 10:46:38 +0000 |
| Subject: | Re: currency conversion | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-39880@lists.php.net to get a copy of this message | ||
>>>>> "c" == christian <chaines@webwork.com.au> writes:
> does anyone know of a way to currency conversions with php? i want
> to grab the current currency from some kind of web site and then
> convert money to different currency value
I'm sure plenty of people have done this properly, but here's a
quick hack to use Xe's currency converter.
<?php
class currency
{
function convert($amount, $from, $to) {
$regex = "/[0-9.]+\s*$from\s*=\s*([0-9.]+)\s*$to/";
$return = file ("http://www.xe.net/ucc/convert.cgi?Amount=1&From=$from&To=$to");
foreach ($return as $line) {
if( preg_match($regex, $line, $match) ) break;
}
if (!isset($match)) return false;
return $amount * $match[1];
}
}
$money = new currency;
print $money->convert( 10, "GBP", "AUD" );
?>
--
Robin Vickery.................................................
BlueCarrots, 14th Floor, 20 Eastbourne Terrace, London, W2 6LE