Re: currency conversion
| From: | Adrian Murphy | Date: | Thu, 15 Feb 2001 13:33:34 +0000 |
| Subject: | Re: currency conversion | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-39897@lists.php.net to get a copy of this message | ||
How legal is this?
can u use it on a website?
free?
----- Original Message -----
From: Robin Vickery <robin@planet-three.co.uk>
To: <php-general@lists.php.net>
Sent: Thursday, February 15, 2001 10:46 AM
Subject: Re: [PHP] currency conversion
> >>>>> "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
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>