0

任何可以解决这个问题的正则表达式专家?基本上,在所有不同的场景中都需要相同的输出。只需要找出正确的正则表达式。

<?php

 // Inputs
$numbers = array(
"1234",
"1 234,00",
"1234.00",
"1234,00",
"1.234,00",
"1.234.00",
"1,234.00",
"1,234,567.00",
"123,456.00",
"1.234.567,00",
"1 234 567,00",
"-1234",
    );

foreach ($numbers as $number) {
    echo $number . " => " . my_number_format($number) . " <br />";
}

// Currency format
function my_number_format($number){
    // return number_format((double)$number, 2, ',', ' ');
    $number = preg_replace('#(\d),(\d)#','$1$2',$number);

    setlocale(LC_MONETARY, 'sv_SE');
    return money_format('%!i', $number);
}
 ?>
4

0 回答 0