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++) { echo('Current is: '.substr($b, $j, $i).PHP_EOL); if($result = getSimilarSubstring($a, 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/KA3mh
function name:  (null)
number of ops:  10
compiled vars:  !0 = $word_a, !1 = $word_b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   ASSIGN                                                   !0, 'superman'
   29     1        ASSIGN                                                   !1, 'stermastein'
   34     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 = 49
Branch analysis from position: 49
2 jumps found. (Code = 44) Position 1 = 51, Position 2 = 22
Branch analysis from position: 51
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
2 jumps found. (Code = 44) Position 1 = 48, Position 2 = 24
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 51, Position 2 = 22
Branch analysis from position: 51
Branch analysis from position: 22
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 44
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
2 jumps found. (Code = 44) Position 1 = 48, Position 2 = 24
Branch analysis from position: 48
Branch analysis from position: 24
Branch analysis from position: 8
filename:       /in/KA3mh
function name:  getSimilarSubstring
number of ops:  53
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                                                      ->49
   15    22    >   ASSIGN                                                   !4, 0
         23      > JMP                                                      ->45
   17    24    >   INIT_FCALL                                               'substr'
         25        SEND_VAR                                                 !1
         26        SEND_VAR                                                 !4
         27        SEND_VAR                                                 !3
         28        DO_ICALL                                         $17     
         29        CONCAT                                           ~18     'Current+is%3A+', $17
         30        CONCAT                                           ~19     ~18, '%0A'
         31        ECHO                                                     ~19
   18    32        INIT_FCALL_BY_NAME                                       'getSimilarSubstring'
         33        SEND_VAR_EX                                              !0
         34        INIT_FCALL                                               'substr'
         35        SEND_VAR                                                 !1
         36        SEND_VAR                                                 !4
         37        SEND_VAR                                                 !3
         38        DO_ICALL                                         $20     
         39        SEND_VAR_NO_REF_EX                                       $20
         40        DO_FCALL                                      0  $21     
         41        ASSIGN                                           ~22     !5, $21
         42      > JMPZ                                                     ~22, ->44
   20    43    > > RETURN                                                   !5
   15    44    >   PRE_INC                                                  !4
         45    >   SUB                                              ~24     !2, !3
         46        IS_SMALLER                                               !4, ~24
         47      > JMPNZ                                                    ~25, ->24
   13    48    >   PRE_DEC                                                  !3
         49    >   IS_SMALLER                                               0, !3
         50      > JMPNZ                                                    ~27, ->22
   24    51    > > RETURN                                                   ''
   25    52*     > RETURN                                                   null

End of function getsimilarsubstring

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.74 ms | 1403 KiB | 20 Q