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(false!==strpos($a, $result = substr($b, $j, $i))) { return $result; } } } return ''; } $word_a = "superman"; $word_b = "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/PLiJD
function name:  (null)
number of ops:  10
compiled vars:  !0 = $word_a, !1 = $word_b
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                                                 !0
          5        SEND_VAR                                                 !1
          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 = 42
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 22
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 24
Branch analysis from position: 41
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 22
Branch analysis from position: 44
Branch analysis from position: 22
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 37
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 24
Branch analysis from position: 41
Branch analysis from position: 24
Branch analysis from position: 8
filename:       /in/PLiJD
function name:  getSimilarSubstring
number of ops:  46
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                                                      ->42
   15    22    >   ASSIGN                                                   !4, 0
         23      > JMP                                                      ->38
   17    24    >   INIT_FCALL                                               'strpos'
         25        SEND_VAR                                                 !0
         26        INIT_FCALL                                               'substr'
         27        SEND_VAR                                                 !1
         28        SEND_VAR                                                 !4
         29        SEND_VAR                                                 !3
         30        DO_ICALL                                         $17     
         31        ASSIGN                                           ~18     !5, $17
         32        SEND_VAL                                                 ~18
         33        DO_ICALL                                         $19     
         34        TYPE_CHECK                                  1018          $19
         35      > JMPZ                                                     ~20, ->37
   19    36    > > RETURN                                                   !5
   15    37    >   PRE_INC                                                  !4
         38    >   SUB                                              ~22     !2, !3
         39        IS_SMALLER                                               !4, ~22
         40      > JMPNZ                                                    ~23, ->24
   13    41    >   PRE_DEC                                                  !3
         42    >   IS_SMALLER                                               0, !3
         43      > JMPNZ                                                    ~25, ->22
   23    44    > > RETURN                                                   ''
   24    45*     > RETURN                                                   null

End of function getsimilarsubstring

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.84 ms | 1394 KiB | 20 Q