2 に答える
0
次のような正規表現を実行してみることができます (未テスト):
if(preg_match('/([$€])([\d\.]+)\s?([\w]+)[^\(]*\((\d+)\)/',$value,$matches)){
switch($matches[1]){
case '$':
$currency = 'dollar';
break;
case '€':
$currency = 'euro';
break;
// and more for more currencies
}
$number = $matches[2];
switch($matches[3]){
case 'billion':
$number = intval($number*1000000000);
break;
case 'million':
$number = intval($number*1000000);
break;
// and more for more multipliers
}
$year = $matches[4];
}
サポートする必要があるすべての可能な通貨記号を、正規表現の最初の角括弧のペアに追加することを忘れないでください[$€]
。
于 2012-12-27T18:55:30.690 に答える