3v4l.org

run code in 300+ PHP versions simultaneously
<?php $formatter = new \NumberFormatter('de_CH', \NumberFormatter::CURRENCY); $format = $formatter->getPattern(); #$decimalSymbol = $formatter->getSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL); #$groupSymbol = $formatter->getSymbol(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL); #echo $format . ' ' . $decimalSymbol . ' ' . $groupSymbol; $r = form($format); var_dump($r); function form($format) { $pos = strpos($format, ';'); if ($pos !== false) { $format = substr($format, 0, $pos); } $format = preg_replace("/[^0\#\.,]/", "", $format); $totalPrecision = 0; $decimalPoint = strpos($format, '.'); if ($decimalPoint !== false) { $totalPrecision = strlen($format) - (strrpos($format, '.') + 1); } else { $decimalPoint = strlen($format); } $requiredPrecision = $totalPrecision; $t = substr($format, $decimalPoint); $pos = strpos($t, '#'); if ($pos !== false) { $requiredPrecision = strlen($t) - $pos - $totalPrecision; } if (strrpos($format, ',') !== false) { $group = $decimalPoint - strrpos($format, ',') - 1; } else { $group = strrpos($format, '.'); } $integerRequired = strpos($format, '.') - strpos($format, '0'); return [ 'precision' => $totalPrecision, 'requiredPrecision' => $requiredPrecision, 'group' => $group, 'integerRequired' => $integerRequired ]; }
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.32, 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
array(4) { ["precision"]=> int(2) ["requiredPrecision"]=> int(2) ["group"]=> int(3) ["integerRequired"]=> int(1) }
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 array(4) { ["precision"]=> int(2) ["requiredPrecision"]=> int(2) ["group"]=> int(3) ["integerRequired"]=> int(1) }
Output for 8.0.13
Fatal error: Uncaught Error: Class "NumberFormatter" not found in /in/q8XhG:3 Stack trace: #0 {main} thrown in /in/q8XhG on line 3
Process exited with code 255.
Output for 7.3.32 - 7.3.33, 7.4.33
Fatal error: Uncaught Error: Class 'NumberFormatter' not found in /in/q8XhG:3 Stack trace: #0 {main} thrown in /in/q8XhG on line 3
Process exited with code 255.

preferences:
160.28 ms | 401 KiB | 203 Q