php - How can I identify the currency symbol in a string that has both symbol and value in? -


i'm getting data script via xml (not important)... part of data value amount includes currency symbol , amount, example:

["price"]=> string(6) "$65.00" ["price"]=> string(8) "€14.20" 

now, i'm looking way automatically work out bit currency symbol , bit value. can't guarrantee quality of data coming in, example amount £14,000.22 or symbol may not single letter - ie swiss francs - chf.

can point me in right direction? tried code worked dollar symbol not euro symbol:

if (preg_match('/\p{sc}/',trim($price),$matches)) {                 var_dump($matches); } 

output

array(1) {   [0]=>   string(1) "$" } 

for reference looked @ http://www.xe.com/symbols.php list of worlds currency symbols.

i not sure exact source data dealing with. however, in accounting, there different formats different currencies. example currencies prefix currency symbol. others suffix symbol. depending on language of currency, might have different symbols decimal.

/^(\d*)\s*([\d,\.]+)\s*(\d*)$/ 

the above regular expression (javascript flavor, might need escape convert php), match following:

  • €14,20
  • $65.00
  • 65.00usd

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -