Jump to content
MakeWebGames

Recommended Posts

Posted
  function currency_format($amount, $currency='') {
$currency_array = array(
	'GBP' => '£', 
	'JPY' => '¥', 
	'CNY' => '¥', 
	'EUR' => '€', 
	'USD' => '$',
	'' => ''
);
     if ( (ctype_alpha($currency) OR empty($currency)) && array_key_exists($currency, $currency_array) && ctype_digit($amount) ) {
	$ret_txt = '<span style="font-weight: bold;">'.$currency_array[$currency].'</span>'.number_format($amount);
     } else {
	$ret_txt = FALSE;
     }
return $ret_txt;
 }
$var = '2001';
echo currency_format($var, 'USD'); // outputs $2,001
echo currency_format($var, 'GBP'); // outputs £2,001
echo currency_format($var, 'JPY'); // outputs ¥2,001
echo currency_format($var, 'CNY'); // outputs ¥2,001
echo currency_format($var, 'EUR'); // outputs €2,001
echo currency_format($var); // outputs 2,001
echo currency_format($var, 'lol'); // fails
echo currency_format('+'.$var, 'USD'); // fails

I was bored and needed something like this so i made it and thought i'd post my result

Posted
function exchangeRate( $amount, $currency, $exchangeIn )
{
   $googleQuery = $amount . ' ' . $currency . ' in ' . $exchangeIn;
   $googleQuery = urlEncode( $googleQuery );
   $askGoogle = file_get_contents( 'http://www.google.com/search?q=' . $googleQuery );
   $askGoogle = strip_tags( $askGoogle );
   $matches = array();
   preg_match( '/= (([0-9]|\.|,|\ )*)/', $askGoogle, $matches );
   return $matches[1] ? $matches[1] : false;
}

echo exchangeRate( 1000, 'euro', 'dollars' );

 

This what you mean?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...