How to obtain the corresponding LOCALE information through the currency symbol 'CURRENCY'.

WBOY
Release: 2016-08-25 10:37:17
Original
1432 people have browsed it

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

But accept_language is not normal locale information

So is there a way to get locale through currency

Reply content:

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

But accept_language is not normal locale information

So is there a way to get locale through currency

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template