3v4l.org

run code in 300+ PHP versions simultaneously
<?php $inputString = "1-234 567-893"; $pattern = '/[ \-]/'; $replacement = ''; $inputString = preg_replace($pattern,$replacement,$inputString); $inputString = trim($inputString); $count = strlen($inputString); //echo $inputString;exit; $rem = ($count%3); $pos = 0; if ($rem == 1){ $pos =4; $count = ($count - $pos); } else if($rem == 2) { $pos = 2; $count = ($count - $pos); } $phoneNumber = ""; for($k=0;$k<$count;$k++){ if($k % 3 !=0 || $k == 0){ $phoneNumber = $phoneNumber.$inputString[$k]; $phoneNumber = trim($phoneNumber); }else{ $phoneNumber = $phoneNumber.'-'; } } echo $phoneNumber;exit; if($rem == 2){ $phoneNumber.= '-'.$inputString[$count+1].$inputString[$count+2]; }else if($rem == 1){ $phoneNumber.= '-'.$inputString[$count+1].$inputString[$count+2].'-'.$inputString[$count+3].$inputString[$count+4]; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 24
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
2 jumps found. (Code = 44) Position 1 = 51, Position 2 = 32
Branch analysis from position: 51
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 32
2 jumps found. (Code = 47) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 46
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 51, Position 2 = 32
Branch analysis from position: 51
Branch analysis from position: 32
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 51, Position 2 = 32
Branch analysis from position: 51
Branch analysis from position: 32
Branch analysis from position: 37
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 29
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
Branch analysis from position: 29
filename:       /in/1D3Om
function name:  (null)
number of ops:  80
compiled vars:  !0 = $inputString, !1 = $pattern, !2 = $replacement, !3 = $count, !4 = $rem, !5 = $pos, !6 = $phoneNumber, !7 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '1-234+567-893'
    4     1        ASSIGN                                                   !1, '%2F%5B+%5C-%5D%2F'
    5     2        ASSIGN                                                   !2, ''
    6     3        INIT_FCALL                                               'preg_replace'
          4        SEND_VAR                                                 !1
          5        SEND_VAR                                                 !2
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $11     
          8        ASSIGN                                                   !0, $11
    7     9        INIT_FCALL                                               'trim'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $13     
         12        ASSIGN                                                   !0, $13
    8    13        STRLEN                                           ~15     !0
         14        ASSIGN                                                   !3, ~15
   10    15        MOD                                              ~17     !3, 3
         16        ASSIGN                                                   !4, ~17
   11    17        ASSIGN                                                   !5, 0
   12    18        IS_EQUAL                                                 !4, 1
         19      > JMPZ                                                     ~20, ->24
   13    20    >   ASSIGN                                                   !5, 4
   14    21        SUB                                              ~22     !3, !5
         22        ASSIGN                                                   !3, ~22
         23      > JMP                                                      ->29
   16    24    >   IS_EQUAL                                                 !4, 2
         25      > JMPZ                                                     ~24, ->29
   18    26    >   ASSIGN                                                   !5, 2
   19    27        SUB                                              ~26     !3, !5
         28        ASSIGN                                                   !3, ~26
   21    29    >   ASSIGN                                                   !6, ''
   22    30        ASSIGN                                                   !7, 0
         31      > JMP                                                      ->49
   24    32    >   MOD                                              ~30     !7, 3
         33        IS_NOT_EQUAL                                     ~31     ~30, 0
         34      > JMPNZ_EX                                         ~31     ~31, ->37
         35    >   IS_EQUAL                                         ~32     !7, 0
         36        BOOL                                             ~31     ~32
         37    > > JMPZ                                                     ~31, ->46
   25    38    >   FETCH_DIM_R                                      ~33     !0, !7
         39        CONCAT                                           ~34     !6, ~33
         40        ASSIGN                                                   !6, ~34
   26    41        INIT_FCALL                                               'trim'
         42        SEND_VAR                                                 !6
         43        DO_ICALL                                         $36     
         44        ASSIGN                                                   !6, $36
         45      > JMP                                                      ->48
   28    46    >   CONCAT                                           ~38     !6, '-'
         47        ASSIGN                                                   !6, ~38
   22    48    >   PRE_INC                                                  !7
         49    >   IS_SMALLER                                               !7, !3
         50      > JMPNZ                                                    ~41, ->32
   31    51    >   ECHO                                                     !6
         52      > EXIT                                                     
   32    53*       IS_EQUAL                                                 !4, 2
         54*       JMPZ                                                     ~42, ->63
   33    55*       ADD                                              ~43     !3, 1
         56*       FETCH_DIM_R                                      ~44     !0, ~43
         57*       CONCAT                                           ~45     '-', ~44
         58*       ADD                                              ~46     !3, 2
         59*       FETCH_DIM_R                                      ~47     !0, ~46
         60*       CONCAT                                           ~48     ~45, ~47
         61*       ASSIGN_OP                                     8          !6, ~48
         62*       JMP                                                      ->79
   34    63*       IS_EQUAL                                                 !4, 1
         64*       JMPZ                                                     ~50, ->79
   35    65*       ADD                                              ~51     !3, 1
         66*       FETCH_DIM_R                                      ~52     !0, ~51
         67*       CONCAT                                           ~53     '-', ~52
         68*       ADD                                              ~54     !3, 2
         69*       FETCH_DIM_R                                      ~55     !0, ~54
         70*       CONCAT                                           ~56     ~53, ~55
         71*       CONCAT                                           ~57     ~56, '-'
         72*       ADD                                              ~58     !3, 3
         73*       FETCH_DIM_R                                      ~59     !0, ~58
         74*       CONCAT                                           ~60     ~57, ~59
         75*       ADD                                              ~61     !3, 4
         76*       FETCH_DIM_R                                      ~62     !0, ~61
         77*       CONCAT                                           ~63     ~60, ~62
         78*       ASSIGN_OP                                     8          !6, ~63
   36    79*     > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.6 ms | 1396 KiB | 17 Q