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 ) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/226q9
function name:  (null)
number of ops:  22
compiled vars:  !0 = $usPhone, !1 = $regex, !2 = $f, !3 = $mapping
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '800-000-7755'
    5     1        ASSIGN                                                   !1, '%7E%0A+%28%3F%3A%0A++++%5Cb%28%5B1-9%5D0%7B2%2C%7D%29%5Cb+%23+1%3A+hundreds%2C+thousands%2C+etc%0A++++%7C%28%5Cd%29%5C2%2B+++++++++%23+2%3A+multiples%0A++++%7C%280%29+++++++++++++%23+3%3A+zero%0A++++%7C%28%5B1-9%5D%29+++++++++%23+4%3A+single+digit%0A+%29%0A+-%3F++++++++++++++++++%23+consume+optional+delimiter%0A%7Ex'
   17     2        NEW                                              $6      'NumberFormatter'
          3        SEND_VAL_EX                                              'en'
          4        FETCH_CLASS_CONSTANT                             ~7      'NumberFormatter', 'SPELLOUT'
          5        SEND_VAL_EX                                              ~7
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !2, $6
   18     8        ASSIGN                                                   !3, <array>
   30     9        INIT_FCALL                                               'ltrim'
   31    10        INIT_FCALL                                               'preg_replace_callback'
   32    11        SEND_VAR                                                 !1
   33    12        DECLARE_LAMBDA_FUNCTION                          ~11     [0]
         13        BIND_LEXICAL                                             ~11, !2
         14        BIND_LEXICAL                                             ~11, !3
   37    15        SEND_VAL                                                 ~11
   38    16        SEND_VAR                                                 !0
   31    17        DO_ICALL                                         $12     
   38    18        SEND_VAR                                                 $12
   30    19        DO_ICALL                                         $13     
   38    20        ECHO                                                     $13
   40    21      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
4 jumps found. (Code = 195) Position 1 = 7, Position 2 = 7, Position 3 = 14, Position 4 = 35
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 31
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
filename:       /in/226q9
function name:  {closure}
number of ops:  41
compiled vars:  !0 = $m, !1 = $f, !2 = $mapping
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
          3        INIT_FCALL                                               'array_key_last'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $3      
          6      > MATCH                                                    $3, [ 1:->7, 4:->7, 2:->14, ], ->35
   34     7    >   INIT_METHOD_CALL                                         !1, 'format'
          8        FETCH_DIM_R                                      ~5      !0, 0
          9        CAST                                          4  ~6      ~5
         10        SEND_VAL_EX                                              ~6
         11        DO_FCALL                                      0  $7      
         12        QM_ASSIGN                                        ~8      $7
         13      > JMP                                                      ->37
   35    14    >   INIT_FCALL                                               'rtrim'
         15        FETCH_DIM_R                                      ~9      !0, 0
         16        SEND_VAL                                                 ~9
         17        SEND_VAL                                                 '-'
         18        DO_ICALL                                         $10     
         19        STRLEN                                           ~11     $10
         20        FETCH_DIM_R                                      ~12     !2, ~11
         21        CONCAT                                           ~13     ~12, '+'
         22        FETCH_DIM_R                                      ~14     !0, 2
         23      > JMPZ                                                     ~14, ->31
         24    >   INIT_METHOD_CALL                                         !1, 'format'
         25        FETCH_DIM_R                                      ~15     !0, 2
         26        CAST                                          4  ~16     ~15
         27        SEND_VAL_EX                                              ~16
         28        DO_FCALL                                      0  $17     
         29        QM_ASSIGN                                        ~18     $17
         30      > JMP                                                      ->32
         31    >   QM_ASSIGN                                        ~18     'oh'
         32    >   CONCAT                                           ~19     ~13, ~18
         33        QM_ASSIGN                                        ~8      ~19
         34      > JMP                                                      ->37
   36    35    >   QM_ASSIGN                                        ~8      'oh'
         36      > JMP                                                      ->37
         37    >   FREE                                                     $3
         38        CONCAT                                           ~20     '+', ~8
         39      > RETURN                                                   ~20
   37    40*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.96 ms | 1010 KiB | 17 Q