fork download
  1. <?php
  2. function formatFromMaskMoney($value) {
  3. if (preg_match('/^[0-9.]+[,]( |)\d{2}$/', $value) !== 0) {
  4. $value = str_replace(' ', '', $value);
  5. $value = str_replace('.', '', $value);
  6. $value = str_replace(',', '.', $value);
  7. $value = number_format($value, 2, ',', '.');
  8. }
  9.  
  10. return $value;
  11. }
  12.  
  13. //Simula POST
  14. $test = array(
  15. 'a' => '1.000.000,00',
  16. 'b' => '3.456.789, 12',
  17. 'c' => '4.233.456.700, 99'
  18. );
  19.  
  20. $test = array_map('formatFromMaskMoney', $test);
  21. print_r($test);//Para verificar os dados antes de usa-los.
Success #stdin #stdout 0.02s 24400KB
stdin
Standard input is empty
stdout
Array
(
    [a] => 1.000.000,00
    [b] => 3.456.789,12
    [c] => 4.233.456.700,99
)