3v4l.org

run code in 300+ PHP versions simultaneously
<?php function gen_explode($delimiter, $string, $limit=NULL) { $offset = 0; $count = 0; $dlen = strlen($delimiter); $len = strlen($string); while( ($pos = strpos($string, $delimiter, $offset)) !== false ) { if( !is_null($limit) && $count++ >= $limit ) { return; } yield substr($string, $offset, $pos-$offset); $offset = $pos + $dlen; } if( $offset == $len ) { yield ''; // replicate explode() empty trailing groups } else if( $offset < $len ) { yield substr($string, $offset); } } $input = "1||50||£---2||25||£---3||25||£---"; foreach( gen_explode('---', $input, 3) as $piece ) { var_dump($piece); foreach( gen_explode('||', $piece) as $smaller_piece ) { var_dump($smaller_piece); } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 23
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 23
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 21
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 21
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 21
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/trmW4
function name:  (null)
number of ops:  25
compiled vars:  !0 = $input, !1 = $piece, !2 = $smaller_piece
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   ASSIGN                                                   !0, '1%7C%7C50%7C%7C%C2%A3---2%7C%7C25%7C%7C%C2%A3---3%7C%7C25%7C%7C%C2%A3---'
   24     1        INIT_FCALL                                               'gen_explode'
          2        SEND_VAL                                                 '---'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 3
          5        DO_FCALL                                      0  $4      
          6      > FE_RESET_R                                       $5      $4, ->23
          7    > > FE_FETCH_R                                               $5, !1, ->23
   25     8    >   INIT_FCALL                                               'var_dump'
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                                 
   26    11        INIT_FCALL                                               'gen_explode'
         12        SEND_VAL                                                 '%7C%7C'
         13        SEND_VAR                                                 !1
         14        DO_FCALL                                      0  $7      
         15      > FE_RESET_R                                       $8      $7, ->21
         16    > > FE_FETCH_R                                               $8, !2, ->21
   27    17    >   INIT_FCALL                                               'var_dump'
         18        SEND_VAR                                                 !2
         19        DO_ICALL                                                 
   26    20      > JMP                                                      ->16
         21    >   FE_FREE                                                  $8
   24    22      > JMP                                                      ->7
         23    >   FE_FREE                                                  $5
   29    24      > RETURN                                                   1

Function gen_explode:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 11
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 40
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 47
Branch analysis from position: 42
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 47
Branch analysis from position: 11
2 jumps found. (Code = 46) Position 1 = 14, Position 2 = 17
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 19
Branch analysis from position: 18
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 11
Branch analysis from position: 36
Branch analysis from position: 11
Branch analysis from position: 17
filename:       /in/trmW4
function name:  gen_explode
number of ops:  48
compiled vars:  !0 = $delimiter, !1 = $string, !2 = $limit, !3 = $offset, !4 = $count, !5 = $dlen, !6 = $len, !7 = $pos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      null
          3        GENERATOR_CREATE                                         
    4     4        ASSIGN                                                   !3, 0
    5     5        ASSIGN                                                   !4, 0
    6     6        STRLEN                                           ~10     !0
          7        ASSIGN                                                   !5, ~10
    7     8        STRLEN                                           ~12     !1
          9        ASSIGN                                                   !6, ~12
    8    10      > JMP                                                      ->28
    9    11    >   TYPE_CHECK                                    2  ~14     !2
         12        BOOL_NOT                                         ~15     ~14
         13      > JMPZ_EX                                          ~15     ~15, ->17
         14    >   POST_INC                                         ~16     !4
         15        IS_SMALLER_OR_EQUAL                              ~17     !2, ~16
         16        BOOL                                             ~15     ~17
         17    > > JMPZ                                                     ~15, ->19
   10    18    > > GENERATOR_RETURN                                         
   12    19    >   INIT_FCALL                                               'substr'
         20        SEND_VAR                                                 !1
         21        SEND_VAR                                                 !3
         22        SUB                                              ~18     !7, !3
         23        SEND_VAL                                                 ~18
         24        DO_ICALL                                         $19     
         25        YIELD                                                    $19
   13    26        ADD                                              ~21     !7, !5
         27        ASSIGN                                                   !3, ~21
    8    28    >   INIT_FCALL                                               'strpos'
         29        SEND_VAR                                                 !1
         30        SEND_VAR                                                 !0
         31        SEND_VAR                                                 !3
         32        DO_ICALL                                         $23     
         33        ASSIGN                                           ~24     !7, $23
         34        TYPE_CHECK                                  1018          ~24
         35      > JMPNZ                                                    ~25, ->11
   15    36    >   IS_EQUAL                                                 !3, !6
         37      > JMPZ                                                     ~26, ->40
   16    38    >   YIELD                                                    ''
         39      > JMP                                                      ->47
   17    40    >   IS_SMALLER                                               !3, !6
         41      > JMPZ                                                     ~28, ->47
   18    42    >   INIT_FCALL                                               'substr'
         43        SEND_VAR                                                 !1
         44        SEND_VAR                                                 !3
         45        DO_ICALL                                         $29     
         46        YIELD                                                    $29
   20    47    > > GENERATOR_RETURN                                         

End of function gen_explode

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
178.56 ms | 1407 KiB | 21 Q