Home > Backend Development > PHP Tutorial > How to obtain the corresponding LOCALE information through the currency symbol 'CURRENCY'.

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-08-25 10:37:17
Original
1499 people have browsed it

The reason for this problem is as follows:

There is international recharge service, the information is as follows:

MONEY:₱48.00 CURRENCY:PHP
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:

$locale = ?
$money  = '₱48.00';
$currency = 'PHP';
$fmt    = new NumberFormatter($locale, NumberFormatter::CURRENCY);
$__     = $fmt->parseCurrency($money, $currency);
var_dump($__)
//$__ === false为转换失败,若为float 则转换成功
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:

$locale = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
var_dump($locale);
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:

MONEY:₱48.00 CURRENCY:PHP
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:

$locale = ?
$money  = '₱48.00';
$currency = 'PHP';
$fmt    = new NumberFormatter($locale, NumberFormatter::CURRENCY);
$__     = $fmt->parseCurrency($money, $currency);
var_dump($__)
//$__ === false为转换失败,若为float 则转换成功
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:

$locale = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
var_dump($locale);
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
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template