3v4l.org

run code in 300+ PHP versions simultaneously
<?php $pattern = "~([^\d.,]|[.,](?!\d{2}$))|(,)~m"; $strings = [ "2.578,20", "2 354,20", "234", "234,256.20", "234,205", "246 548", "244'056", "26'155.25", "12,20", "13.33", ]; foreach ($strings as $string) { echo preg_replace_callback($pattern, function ($matches) { if (isset($matches[2])) return "."; if (isset($matches[1])) return ""; }, $string) . PHP_EOL; }
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.15, 8.5.0
2578.20 2354.20 234 234256.20 234205 246548 244056 26155.25 12.20 13.33
Output for 8.3.28
/bin/php-8.3.28: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.3.28) /bin/php-8.3.28: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.3.28) /bin/php-8.3.28: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.3.28) /bin/php-8.3.28: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.3.28)
Process exited with code 1.

preferences:
186.11 ms | 407 KiB | 5 Q