3v4l.org

run code in 300+ PHP versions simultaneously
<?php function get_between($the_string, $starts_with, $ends_with) { $the_string = substr($the_string,strpos ($the_string , $starts_with)); $temp = explode($starts_with, $the_string); $result_array = array(); $inc = 0; foreach($temp as $a_start_match) { //echo $inc; if (strlen($ends_with) <= strlen($a_start_match)) { echo "testing ".substr($a_start_match, -strlen($ends_with))." against ".$ends_with."\n"; if(substr($a_start_match, -strlen($ends_with)) === $ends_with) { $result_array[$inc]=$a_start_match; $inc++; } } } return $result_array; } $the_string = "some string here string_1---1-----string2 some string here string_1----2----string2 some string here string_1----3----string2"; $a = "string_1"; $b = "string2"; print_R (get_between($the_string,$a,$b));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CfoYe
function name:  (null)
number of ops:  12
compiled vars:  !0 = $the_string, !1 = $a, !2 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   ASSIGN                                                   !0, 'some+string+here+string_1---1-----string2+some+string+here+string_1----2----string2+some+string+here+string_1----3----string2'
   38     1        ASSIGN                                                   !1, 'string_1'
   39     2        ASSIGN                                                   !2, 'string2'
   41     3        INIT_FCALL                                               'print_r'
          4        INIT_FCALL                                               'get_between'
          5        SEND_VAR                                                 !0
          6        SEND_VAR                                                 !1
          7        SEND_VAR                                                 !2
          8        DO_FCALL                                      0  $6      
          9        SEND_VAR                                                 $6
         10        DO_ICALL                                                 
         11      > RETURN                                                   1

Function get_between:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 48
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 48
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 47
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 47
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 47
Branch analysis from position: 47
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 48
filename:       /in/CfoYe
function name:  get_between
number of ops:  51
compiled vars:  !0 = $the_string, !1 = $starts_with, !2 = $ends_with, !3 = $temp, !4 = $result_array, !5 = $inc, !6 = $a_start_match
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    7     3        INIT_FCALL                                               'substr'
          4        SEND_VAR                                                 !0
          5        INIT_FCALL                                               'strpos'
          6        SEND_VAR                                                 !0
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                         $7      
          9        SEND_VAR                                                 $7
         10        DO_ICALL                                         $8      
         11        ASSIGN                                                   !0, $8
    9    12        INIT_FCALL                                               'explode'
         13        SEND_VAR                                                 !1
         14        SEND_VAR                                                 !0
         15        DO_ICALL                                         $10     
         16        ASSIGN                                                   !3, $10
   10    17        ASSIGN                                                   !4, <array>
   12    18        ASSIGN                                                   !5, 0
   14    19      > FE_RESET_R                                       $14     !3, ->48
         20    > > FE_FETCH_R                                               $14, !6, ->48
   17    21    >   STRLEN                                           ~15     !2
         22        STRLEN                                           ~16     !6
         23        IS_SMALLER_OR_EQUAL                                      ~15, ~16
         24      > JMPZ                                                     ~17, ->47
   20    25    >   INIT_FCALL                                               'substr'
         26        SEND_VAR                                                 !6
         27        STRLEN                                           ~18     !2
         28        MUL                                              ~19     ~18, -1
         29        SEND_VAL                                                 ~19
         30        DO_ICALL                                         $20     
         31        CONCAT                                           ~21     'testing+', $20
         32        CONCAT                                           ~22     ~21, '+against+'
         33        CONCAT                                           ~23     ~22, !2
         34        CONCAT                                           ~24     ~23, '%0A'
         35        ECHO                                                     ~24
   21    36        INIT_FCALL                                               'substr'
         37        SEND_VAR                                                 !6
         38        STRLEN                                           ~25     !2
         39        MUL                                              ~26     ~25, -1
         40        SEND_VAL                                                 ~26
         41        DO_ICALL                                         $27     
         42        IS_IDENTICAL                                             !2, $27
         43      > JMPZ                                                     ~28, ->47
   23    44    >   ASSIGN_DIM                                               !4, !5
         45        OP_DATA                                                  !6
   24    46        PRE_INC                                                  !5
   14    47    > > JMP                                                      ->20
         48    >   FE_FREE                                                  $14
   30    49      > RETURN                                                   !4
   31    50*     > RETURN                                                   null

End of function get_between

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.57 ms | 1403 KiB | 22 Q