3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getSimilarSubstring($a, $b) { if(!strlen($a) || !strlen($b)) { return ''; } if(false!==strpos($a, $b)) { return $b; } $length = strlen($b); for($i=$length-1; $i>0; $i--) { for($j=0; $j<$length-$i; $j++) { if($result = getSimilarSubstring($a, substr($b, $j, $i))) { return $result; } } } return ''; } $word_b = "superman"; $word_a = "stermastein"; //$word_a = 'afk'; //$word_b = 'fk'; var_dump(getSimilarSubstring($word_a, $word_b));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BsuUb
function name:  (null)
number of ops:  10
compiled vars:  !0 = $word_b, !1 = $word_a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   ASSIGN                                                   !0, 'superman'
   28     1        ASSIGN                                                   !1, 'stermastein'
   33     2        INIT_FCALL                                               'var_dump'
          3        INIT_FCALL                                               'getsimilarsubstring'
          4        SEND_VAR                                                 !1
          5        SEND_VAR                                                 !0
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Function getsimilarsubstring:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 10
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 17
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
2 jumps found. (Code = 44) Position 1 = 43, Position 2 = 22
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 24
Branch analysis from position: 40
2 jumps found. (Code = 44) Position 1 = 43, Position 2 = 22
Branch analysis from position: 43
Branch analysis from position: 22
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 36
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 24
Branch analysis from position: 40
Branch analysis from position: 24
Branch analysis from position: 8
filename:       /in/BsuUb
function name:  getSimilarSubstring
number of ops:  45
compiled vars:  !0 = $a, !1 = $b, !2 = $length, !3 = $i, !4 = $j, !5 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        STRLEN                                           ~6      !0
          3        BOOL_NOT                                         ~7      ~6
          4      > JMPNZ_EX                                         ~7      ~7, ->8
          5    >   STRLEN                                           ~8      !1
          6        BOOL_NOT                                         ~9      ~8
          7        BOOL                                             ~7      ~9
          8    > > JMPZ                                                     ~7, ->10
    6     9    > > RETURN                                                   ''
    8    10    >   INIT_FCALL                                               'strpos'
         11        SEND_VAR                                                 !0
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $10     
         14        TYPE_CHECK                                  1018          $10
         15      > JMPZ                                                     ~11, ->17
   10    16    > > RETURN                                                   !1
   12    17    >   STRLEN                                           ~12     !1
         18        ASSIGN                                                   !2, ~12
   13    19        SUB                                              ~14     !2, 1
         20        ASSIGN                                                   !3, ~14
         21      > JMP                                                      ->41
   15    22    >   ASSIGN                                                   !4, 0
         23      > JMP                                                      ->37
   17    24    >   INIT_FCALL_BY_NAME                                       'getSimilarSubstring'
         25        SEND_VAR_EX                                              !0
         26        INIT_FCALL                                               'substr'
         27        SEND_VAR                                                 !1
         28        SEND_VAR                                                 !4
         29        SEND_VAR                                                 !3
         30        DO_ICALL                                         $17     
         31        SEND_VAR_NO_REF_EX                                       $17
         32        DO_FCALL                                      0  $18     
         33        ASSIGN                                           ~19     !5, $18
         34      > JMPZ                                                     ~19, ->36
   19    35    > > RETURN                                                   !5
   15    36    >   PRE_INC                                                  !4
         37    >   SUB                                              ~21     !2, !3
         38        IS_SMALLER                                               !4, ~21
         39      > JMPNZ                                                    ~22, ->24
   13    40    >   PRE_DEC                                                  !3
         41    >   IS_SMALLER                                               0, !3
         42      > JMPNZ                                                    ~24, ->22
   23    43    > > RETURN                                                   ''
   24    44*     > RETURN                                                   null

End of function getsimilarsubstring

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.66 ms | 1403 KiB | 20 Q