3v4l.org

run code in 300+ PHP versions simultaneously
<?php $usPhone = '800-000-7755'; $regex = <<<'REGEX' ~ (?: \b([1-9]0{2,})\b # 1: hundreds, thousands, etc |(\d)\2+ # 2: multiples |(0) # 3: zero |([1-9]) # 4: single digit ) -? # consume optional delimiter ~x REGEX; $f = new NumberFormatter('en', NumberFormatter::SPELLOUT); $mapping = [ 2 => 'double', 3 => 'triple', 4 => 'quadruple', 5 => 'quintuple', 6 => 'sextuple', 7 => 'septuple', 8 => 'octuple', 9 => 'nonuple', 10 => 'decuple', ]; echo ltrim( preg_replace_callback( $regex, fn($m) => ' ' . match (array_key_last($m)) { 1, 4 => $f->format((int)$m[0]), 2 => $mapping[strlen(rtrim($m[0], '-'))] . " " . ($m[2] ? $f->format((int)$m[2]) : 'oh'), default => 'oh', }, $usPhone ) );
Output for 8.5.1
Fatal error: Uncaught Error: Class "NumberFormatter" not found in /in/226q9:17 Stack trace: #0 {main} thrown in /in/226q9 on line 17
Process exited with code 255.
Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.4.16, 8.5.0
eight hundred triple oh double seven double five
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
76.9 ms | 408 KiB | 5 Q