Home > Article > Backend Development > How to obtain the corresponding LOCALE information through the currency symbol 'CURRENCY'.
The reason for this problem is as follows:
There is international recharge service, the information is as follows:
<code class="shell">MONEY:₱48.00 CURRENCY:PHP</code>
Where money is the recharge amount (the amount of the current locale), and currency is the currency information corresponding to money.
For the convenience of statistical accounting, I want to convert money ₱48.00
into floating point number information that can be recognized by the naked eye.
So we used the official PHP intl
extension to develop the following code:
<code class="php">$locale = ? $money = '₱48.00'; $currency = 'PHP'; $fmt = new NumberFormatter($locale, NumberFormatter::CURRENCY); $__ = $fmt->parseCurrency($money, $currency); var_dump($__) //$__ === false为转换失败,若为float 则转换成功</code>
Unexpectedly, we encountered the difficulty of not being able to obtain the locale
information. We then used intl
in locale
to obtain the following:
<code class="php">$locale = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']); var_dump($locale);</code>
But accept_language is not normal locale information
So is there a way to get locale
through
currency
The reason for this problem is as follows:
There is international recharge service, the information is as follows:
<code class="shell">MONEY:₱48.00 CURRENCY:PHP</code>
Where money is the recharge amount (the amount of the current locale), and currency is the currency information corresponding to money.
For the convenience of statistical accounting, I want to convert money ₱48.00
into floating point number information that can be recognized by the naked eye.
So we used the official PHP intl
extension to develop the following code:
<code class="php">$locale = ? $money = '₱48.00'; $currency = 'PHP'; $fmt = new NumberFormatter($locale, NumberFormatter::CURRENCY); $__ = $fmt->parseCurrency($money, $currency); var_dump($__) //$__ === false为转换失败,若为float 则转换成功</code>
Unexpectedly, we encountered the difficulty of not being able to obtain the locale
information. We then used intl
in locale
to obtain the following:
<code class="php">$locale = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']); var_dump($locale);</code>
But accept_language is not normal locale information
So is there a way to get locale
through
currency