3v4l.org

run code in 300+ PHP versions simultaneously
<?php function regexp($string, $pattern) { return preg_match('/'.$pattern.'/', $string); } function getLeftDelimiter($string, $pattern) { $result = ''; while(1) { $current = $string; $position = strlen($string); while($position && regexp($current, $pattern)) { $position--; $current = substr($current, 0, -1); } $current = substr($string, 0, $position+1); if(regexp($current, '^('.$pattern.')$')) { $result .= $current; $string = substr($string, $position+1); } else { return $result; } } } function getRightDelimiter($string, $pattern) { $result = ''; while(1) { $current = $string; $position = 0; while($position<strlen($string) && regexp($current, $pattern)) { $position++; $current = substr($current, 1); } $current = substr($string, $position-1); if(regexp($current, '^('.$pattern.')$')) { $result = $current.$result; $string = substr($string, 0, $position-1); } else { return $result; } } } function getLeftChunk($string, $pattern) { $result = ''; $current = ''; $position= 0; while($position<strlen($string) && !regexp($current, $pattern)) { $position++; $current = substr($string, 0, $position); } $delimiter = getRightDelimiter($current, $pattern); return substr($current, 0, strlen($current)-strlen($delimiter)); } function regexpSplit($string, $pattern) { $result = []; $i = 0; while($string && ++$i<10) { $delimiter = getLeftDelimiter($string, $pattern); if($delimiter==$string) { break; } $string = substr($string, strlen($delimiter)); $chunk = getLeftChunk($string, $pattern); $string = substr($string, strlen($chunk)); $result[] = $chunk; } return $result; } $string = 'tbarbarfob12baz 56bar'; $pattern = 'bar|baz'; var_dump(regexpSplit($string, $pattern));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/81W3V
function name:  (null)
number of ops:  10
compiled vars:  !0 = $string, !1 = $pattern
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   91     0  E >   ASSIGN                                                   !0, 'tbarbarfob12baz+56bar'
   92     1        ASSIGN                                                   !1, 'bar%7Cbaz'
   93     2        INIT_FCALL                                               'var_dump'
          3        INIT_FCALL                                               'regexpsplit'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Function regexp:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/81W3V
function name:  regexp
number of ops:  10
compiled vars:  !0 = $string, !1 = $pattern
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        INIT_FCALL                                               'preg_match'
          3        CONCAT                                           ~2      '%2F', !1
          4        CONCAT                                           ~3      ~2, '%2F'
          5        SEND_VAL                                                 ~3
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $4      
          8      > RETURN                                                   $4
    6     9*     > RETURN                                                   null

End of function regexp

Function getleftdelimiter:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
2 jumps found. (Code = 44) Position 1 = 46, Position 2 = 4
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
2 jumps found. (Code = 46) Position 1 = 16, Position 2 = 21
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 8
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 44
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 46) Position 1 = 16, Position 2 = 21
Branch analysis from position: 16
Branch analysis from position: 21
Branch analysis from position: 21
filename:       /in/81W3V
function name:  getLeftDelimiter
number of ops:  47
compiled vars:  !0 = $string, !1 = $pattern, !2 = $result, !3 = $current, !4 = $position
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   10     2        ASSIGN                                                   !2, ''
   11     3      > JMP                                                      ->45
   13     4    >   ASSIGN                                                   !3, !0
   14     5        STRLEN                                           ~7      !0
          6        ASSIGN                                                   !4, ~7
   15     7      > JMP                                                      ->15
   17     8    >   PRE_DEC                                                  !4
   18     9        INIT_FCALL                                               'substr'
         10        SEND_VAR                                                 !3
         11        SEND_VAL                                                 0
         12        SEND_VAL                                                 -1
         13        DO_ICALL                                         $10     
         14        ASSIGN                                                   !3, $10
   15    15    > > JMPZ_EX                                          ~12     !4, ->21
         16    >   INIT_FCALL                                               'regexp'
         17        SEND_VAR                                                 !3
         18        SEND_VAR                                                 !1
         19        DO_FCALL                                      0  $13     
         20        BOOL                                             ~12     $13
         21    > > JMPNZ                                                    ~12, ->8
   20    22    >   INIT_FCALL                                               'substr'
         23        SEND_VAR                                                 !0
         24        SEND_VAL                                                 0
         25        ADD                                              ~14     !4, 1
         26        SEND_VAL                                                 ~14
         27        DO_ICALL                                         $15     
         28        ASSIGN                                                   !3, $15
   21    29        INIT_FCALL                                               'regexp'
         30        SEND_VAR                                                 !3
         31        CONCAT                                           ~17     '%5E%28', !1
         32        CONCAT                                           ~18     ~17, '%29%24'
         33        SEND_VAL                                                 ~18
         34        DO_FCALL                                      0  $19     
         35      > JMPZ                                                     $19, ->44
   23    36    >   ASSIGN_OP                                     8          !2, !3
   24    37        INIT_FCALL                                               'substr'
         38        SEND_VAR                                                 !0
         39        ADD                                              ~21     !4, 1
         40        SEND_VAL                                                 ~21
         41        DO_ICALL                                         $22     
         42        ASSIGN                                                   !0, $22
         43      > JMP                                                      ->45
   28    44    > > RETURN                                                   !2
   11    45    > > JMPNZ                                                    1, ->4
   31    46    > > RETURN                                                   null

End of function getleftdelimiter

Function getrightdelimiter:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 4
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 46) Position 1 = 16, Position 2 = 21
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 7
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 45
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 46) Position 1 = 16, Position 2 = 21
Branch analysis from position: 16
Branch analysis from position: 21
Branch analysis from position: 21
filename:       /in/81W3V
function name:  getRightDelimiter
number of ops:  48
compiled vars:  !0 = $string, !1 = $pattern, !2 = $result, !3 = $current, !4 = $position
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   35     2        ASSIGN                                                   !2, ''
   36     3      > JMP                                                      ->46
   38     4    >   ASSIGN                                                   !3, !0
   39     5        ASSIGN                                                   !4, 0
   40     6      > JMP                                                      ->13
   42     7    >   PRE_INC                                                  !4
   43     8        INIT_FCALL                                               'substr'
          9        SEND_VAR                                                 !3
         10        SEND_VAL                                                 1
         11        DO_ICALL                                         $9      
         12        ASSIGN                                                   !3, $9
   40    13    >   STRLEN                                           ~11     !0
         14        IS_SMALLER                                       ~12     !4, ~11
         15      > JMPZ_EX                                          ~12     ~12, ->21
         16    >   INIT_FCALL                                               'regexp'
         17        SEND_VAR                                                 !3
         18        SEND_VAR                                                 !1
         19        DO_FCALL                                      0  $13     
         20        BOOL                                             ~12     $13
         21    > > JMPNZ                                                    ~12, ->7
   45    22    >   INIT_FCALL                                               'substr'
         23        SEND_VAR                                                 !0
         24        SUB                                              ~14     !4, 1
         25        SEND_VAL                                                 ~14
         26        DO_ICALL                                         $15     
         27        ASSIGN                                                   !3, $15
   46    28        INIT_FCALL                                               'regexp'
         29        SEND_VAR                                                 !3
         30        CONCAT                                           ~17     '%5E%28', !1
         31        CONCAT                                           ~18     ~17, '%29%24'
         32        SEND_VAL                                                 ~18
         33        DO_FCALL                                      0  $19     
         34      > JMPZ                                                     $19, ->45
   48    35    >   CONCAT                                           ~20     !3, !2
         36        ASSIGN                                                   !2, ~20
   49    37        INIT_FCALL                                               'substr'
         38        SEND_VAR                                                 !0
         39        SEND_VAL                                                 0
         40        SUB                                              ~22     !4, 1
         41        SEND_VAL                                                 ~22
         42        DO_ICALL                                         $23     
         43        ASSIGN                                                   !0, $23
         44      > JMP                                                      ->46
   53    45    > > RETURN                                                   !2
   36    46    > > JMPNZ                                                    1, ->4
   56    47    > > RETURN                                                   null

End of function getrightdelimiter

Function getleftchunk:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 46) Position 1 = 16, Position 2 = 22
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 6
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 46) Position 1 = 16, Position 2 = 22
Branch analysis from position: 16
Branch analysis from position: 22
Branch analysis from position: 22
filename:       /in/81W3V
function name:  getLeftChunk
number of ops:  38
compiled vars:  !0 = $string, !1 = $pattern, !2 = $result, !3 = $current, !4 = $position, !5 = $delimiter
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   60     2        ASSIGN                                                   !2, ''
   61     3        ASSIGN                                                   !3, ''
   62     4        ASSIGN                                                   !4, 0
   63     5      > JMP                                                      ->13
   65     6    >   PRE_INC                                                  !4
   66     7        INIT_FCALL                                               'substr'
          8        SEND_VAR                                                 !0
          9        SEND_VAL                                                 0
         10        SEND_VAR                                                 !4
         11        DO_ICALL                                         $10     
         12        ASSIGN                                                   !3, $10
   63    13    >   STRLEN                                           ~12     !0
         14        IS_SMALLER                                       ~13     !4, ~12
         15      > JMPZ_EX                                          ~13     ~13, ->22
         16    >   INIT_FCALL                                               'regexp'
         17        SEND_VAR                                                 !3
         18        SEND_VAR                                                 !1
         19        DO_FCALL                                      0  $14     
         20        BOOL_NOT                                         ~15     $14
         21        BOOL                                             ~13     ~15
         22    > > JMPNZ                                                    ~13, ->6
   68    23    >   INIT_FCALL                                               'getrightdelimiter'
         24        SEND_VAR                                                 !3
         25        SEND_VAR                                                 !1
         26        DO_FCALL                                      0  $16     
         27        ASSIGN                                                   !5, $16
   69    28        INIT_FCALL                                               'substr'
         29        SEND_VAR                                                 !3
         30        SEND_VAL                                                 0
         31        STRLEN                                           ~18     !3
         32        STRLEN                                           ~19     !5
         33        SUB                                              ~20     ~18, ~19
         34        SEND_VAL                                                 ~20
         35        DO_ICALL                                         $21     
         36      > RETURN                                                   $21
   70    37*     > RETURN                                                   null

End of function getleftchunk

Function regexpsplit:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
2 jumps found. (Code = 46) Position 1 = 33, Position 2 = 36
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 5
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 13
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
Branch analysis from position: 13
2 jumps found. (Code = 46) Position 1 = 33, Position 2 = 36
Branch analysis from position: 33
Branch analysis from position: 36
Branch analysis from position: 36
filename:       /in/81W3V
function name:  regexpSplit
number of ops:  39
compiled vars:  !0 = $string, !1 = $pattern, !2 = $result, !3 = $i, !4 = $delimiter, !5 = $chunk
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   72     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   74     2        ASSIGN                                                   !2, <array>
   75     3        ASSIGN                                                   !3, 0
   76     4      > JMP                                                      ->32
   78     5    >   INIT_FCALL                                               'getleftdelimiter'
          6        SEND_VAR                                                 !0
          7        SEND_VAR                                                 !1
          8        DO_FCALL                                      0  $8      
          9        ASSIGN                                                   !4, $8
   79    10        IS_EQUAL                                                 !4, !0
         11      > JMPZ                                                     ~10, ->13
   81    12    > > JMP                                                      ->37
   83    13    >   INIT_FCALL                                               'substr'
         14        SEND_VAR                                                 !0
         15        STRLEN                                           ~11     !4
         16        SEND_VAL                                                 ~11
         17        DO_ICALL                                         $12     
         18        ASSIGN                                                   !0, $12
   84    19        INIT_FCALL                                               'getleftchunk'
         20        SEND_VAR                                                 !0
         21        SEND_VAR                                                 !1
         22        DO_FCALL                                      0  $14     
         23        ASSIGN                                                   !5, $14
   85    24        INIT_FCALL                                               'substr'
         25        SEND_VAR                                                 !0
         26        STRLEN                                           ~16     !5
         27        SEND_VAL                                                 ~16
         28        DO_ICALL                                         $17     
         29        ASSIGN                                                   !0, $17
   86    30        ASSIGN_DIM                                               !2
         31        OP_DATA                                                  !5
   76    32    > > JMPZ_EX                                          ~20     !0, ->36
         33    >   PRE_INC                                          ~21     !3
         34        IS_SMALLER                                       ~22     ~21, 10
         35        BOOL                                             ~20     ~22
         36    > > JMPNZ                                                    ~20, ->5
   88    37    > > RETURN                                                   !2
   89    38*     > RETURN                                                   null

End of function regexpsplit

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
184.58 ms | 1419 KiB | 28 Q