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.

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

1
get_currency_symbol('GBP'); //returns Pound

6 Comments Add Comment