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.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
eight oh oh oh oh oh oh oh ten

preferences:
57.6 ms | 406 KiB | 5 Q