3v4l.org

run code in 300+ PHP versions simultaneously
<?php $usPhone = '800-000-0010'; $regex = <<<'REGEX' ~ (?: ([1-9]\d)(?=(?:\d{2})?$) # 1: double-digit in last segment |(0) # 2: zero |([1-9]) # 3: single digit ) -? # consume optional delimiter ~x REGEX; $f = new NumberFormatter('en', NumberFormatter::SPELLOUT); echo ltrim( preg_replace_callback( $regex, fn($m) => sprintf( ' %s', array_key_last($m) === 2 ? 'oh' : $f->format(intval($m[0])) ), $usPhone ) );
Output for 8.5.1 - 8.5.3
Fatal error: Uncaught Error: Class "NumberFormatter" not found in /in/4OtdB:16 Stack trace: #0 {main} thrown in /in/4OtdB on line 16
Process exited with code 255.
Output for 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0
eight oh oh oh oh oh oh oh ten

preferences:
63.38 ms | 847 KiB | 4 Q