3v4l.org

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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.57 ms | 1404 KiB | 17 Q