Return Currency Symbols using PHP

I needed a PHP function that returns HTML Entity of currency codes, so I have written this small function with list of major currency symbols of the world, I hope this will be useful.
PHP
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
/* get currency symboles */ function get_currency_symbol($cc = 'USD') { $cc = strtoupper($cc); $currency = array( "USD" => "$" , //U.S. Dollar "AUD" => "$" , //Australian Dollar "BRL" => "R$" , //Brazilian Real "CAD" => "C$" , //Canadian Dollar "CZK" => "Kč" , //Czech Koruna "DKK" => "kr" , //Danish Krone "EUR" => "€" , //Euro "HKD" => "&#36" , //Hong Kong Dollar "HUF" => "Ft" , //Hungarian Forint "ILS" => "₪" , //Israeli New Sheqel "INR" => "₹", //Indian Rupee "JPY" => "¥" , //Japanese Yen "MYR" => "RM" , //Malaysian Ringgit "MXN" => "&#36" , //Mexican Peso "NOK" => "kr" , //Norwegian Krone "NZD" => "&#36" , //New Zealand Dollar "PHP" => "₱" , //Philippine Peso "PLN" => "zł" ,//Polish Zloty "GBP" => "£" , //Pound Sterling "SEK" => "kr" , //Swedish Krona "CHF" => "Fr" , //Swiss Franc "TWD" => "$" , //Taiwan New Dollar "THB" => "฿" , //Thai Baht "TRY" => "₺" //Turkish Lira ); if(array_key_exists($cc, $currency)){ return $currency[$cc]; } }

Usage

PHP
  • 1
get_currency_symbol('GBP'); //returns Pound
  • use as dropdown
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    <option value="">USD <option value="">AUD <option value="">BRL <option value="">CAD <option value="">CZK <option value="">DKK <option value="">EUR <option value="">HKD <option value="">HUF <option value="">ILS <option value="">INR <option value="">JPY <option value="">MYR <option value="">MXN <option value="">NOK <option value="">NZD <option value="">PHP <option value="">PLN <option value="">GBP <option value="">SEK <option value="">CHF <option value="">TWD <option value="">THB <option value="">TRY
  • Excellent work Saran, very helpful! FYI: there is a missing comma to break the rupee line - assuming it happened when you updated the code.
New question is currently disabled!