Let\'s start with simple piece of code to format money with NumberFormatter
:
$formatter = new NumberFormatter(\'en_US\', NumberFormatter::CURREN
Since the symbols can be multi-byte I used mb_*() functions to correctly grab the all non-punctuation and non-digit chars which would just leaves the symbol.
function get_currency_symbol($string)
{
$symbol = '';
$length = mb_strlen($string, 'utf-8');
for ($i = 0; $i < $length; $i++)
{
$char = mb_substr($string, $i, 1, 'utf-8');
if (!ctype_digit($char) && !ctype_punct($char))
$symbol .= $char;
}
return $symbol;
}
$format = new NumberFormatter('en_US', NumberFormatter::CURRENCY);
$string = $format->formatCurrency(123456789, 'JPY');
echo get_currency_symbol($string);
Try this variant:
$formatter->getSymbol(NumberFormatter::INTL_CURRENCY_SYMBOL);