3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MoneyHelper { public function getAmount($money) { $cleanString = preg_replace('/[^\d.,-]/', '', $money); $onlyNumbersString = preg_replace('/[^\d-]/', '', $money); $separatorsCountToBeErased = strlen($cleanString) - strlen($onlyNumbersString) - 1; $stringWithCommaOrDot = preg_replace('/[,.]/', '', $cleanString, $separatorsCountToBeErased); $removedThousandSeparator = preg_replace('/[.,](?=\d{3,}$)/', '', $stringWithCommaOrDot); //return (float) str_replace(',', '.', $removedThousandSeparator); return [ 'cleanString' => $cleanString, 'onlyNumbersString' => $onlyNumbersString, 'separatorsCountToBeErased' => $separatorsCountToBeErased, 'stringWithCommaOrDot' => $stringWithCommaOrDot, 'removedThousandSeparator' => $removedThousandSeparator, 'result' => (float) str_replace(',', '.', $removedThousandSeparator) ]; } } $obj = new MoneyHelper; echo var_dump($obj->getAmount('-200.000,54')) ;
Output for git.master, git.master_jit, rfc.property-hooks
array(6) { ["cleanString"]=> string(11) "-200.000,54" ["onlyNumbersString"]=> string(9) "-20000054" ["separatorsCountToBeErased"]=> int(1) ["stringWithCommaOrDot"]=> string(10) "-200000,54" ["removedThousandSeparator"]=> string(10) "-200000,54" ["result"]=> float(-200000.54) }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
19.13 ms | 402 KiB | 8 Q