如何在php变量中检查货币代码?

I want to know what currency code lies in my variable value.

For example:

$var = "$200";
$check = array("$", "AU$", "CA$", "£", "€", "¥");

If $var has "$"
$currency = USD

else if $var has "£"
$currency = GBP

and so on..

What I was trying is:

$result = strpos($var, $check);
if ($result === '$') {
$currency = 'USD';
} else if ($result === '£') {
$currency = 'GBP';
| else ...

you can do like this

$var = "$200";
$check = array("$"=>'USD', "AU$"=>'aus', "CA$"=>'cas', "£"=>'GBP', "€"=>'ee', "¥"=>'yy');

$symbol = str_replace(range(0,9),'',$var);

$currency = $check[$symbol]?$check[$symbol]:'';

You can create an associative array of your currencies and then use the php function array_search to see if the currency you have selected is present in the currencies array.

<?php

$currencies = array(
    'USD' => '$',
    'AUD' => 'AU$',
    'GBP' => '£'
);

$mycurrency = '£';

$key = array_search($mycurrency, $currencies);

if($key) {

    echo 'My currency is ' . $key;
}

?>

preg_match() and a regular expression fit the bill just fine here:

$curr = "$250000";
$sign = null;
preg_match('/\$|AU\$|CA\$|£|€|¥/', $curr, $sign);
switch($sign) {
    case '$':
        // USD
    case 'AU$':
...