从字符串中分割货币和金额 [英] split currency and amount from a string
问题描述
我正在导入一个文件,该文件的金额具有不同的货币符号
I am importing a file which has amount with different currency signs
£12.10
$26.13
€12.50
我需要导入并将其转换为单一货币。我将字符串拆分如下
I need to import and convert this into single currency. I am splitting the string as follows
$parts = split(' ', preg_replace("/([0-9])/", ' ${1}', $amount, 1));
无法通过PREG_SPLIT_DELIM_CAPTURE使preg_split工作
Couldn't make preg_split work with PREG_SPLIT_DELIM_CAPTURE
$parts = preg_split("/\d/", $amount, 2, PREG_SPLIT_DELIM_CAPTURE);
我对货币代码有一系列货币符号
I have an array of currency sign to currency code
$currencySymbols = array('£'=>'GBP', '$'=>'USD','€'=>'EUR')
我需要
1.将字符串拆分为货币符号和值-如果有更好的选择然后我在做什么
2.将货币符号映射到货币代码。无法使用$ currencySymbols [$ parts [0]]
I need to 1. split the string into currency sign and value - if there is a better way then what i am doing 2. map the currency sign to currency code. Not able to map with $currencySymbols[$parts[0]]
进行任何映射,将不胜感激。 (PHP 5.2.6)使用charset = utf-8
Any help will be appreciated. (PHP 5.2.6) using charset=utf-8
非常感谢
推荐答案
您可能应该使用 NumberFormatter :: parseCurrency 来代替
尽管大多数货币符号出现在数值之前的时间,在某些欧洲国家,货币符号最后被写入。
这篇关于从字符串中分割货币和金额的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!