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(sprintf('Current[%s][%s] = %s'.PHP_EOL, $i, $j, substr($b, $j, $i))); if(false!==strpos($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/Ffh81
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 = 53
Branch analysis from position: 53
2 jumps found. (Code = 44) Position 1 = 55, Position 2 = 22
Branch analysis from position: 55
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 24
Branch analysis from position: 52
2 jumps found. (Code = 44) Position 1 = 55, Position 2 = 22
Branch analysis from position: 55
Branch analysis from position: 22
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 48
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 24
Branch analysis from position: 52
Branch analysis from position: 24
Branch analysis from position: 8
filename:       /in/Ffh81
function name:  getSimilarSubstring
number of ops:  57
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                                                      ->53
   15    22    >   ASSIGN                                                   !4, 0
         23      > JMP                                                      ->49
   17    24    >   INIT_FCALL                                               'sprintf'
         25        SEND_VAL                                                 'Current%5B%25s%5D%5B%25s%5D+%3D+%25s%0A'
         26        SEND_VAR                                                 !3
         27        SEND_VAR                                                 !4
         28        INIT_FCALL                                               'substr'
         29        SEND_VAR                                                 !1
         30        SEND_VAR                                                 !4
         31        SEND_VAR                                                 !3
         32        DO_ICALL                                         $17     
         33        SEND_VAR                                                 $17
         34        DO_ICALL                                         $18     
         35        ECHO                                                     $18
   18    36        INIT_FCALL                                               'strpos'
         37        SEND_VAR                                                 !0
         38        INIT_FCALL                                               'substr'
         39        SEND_VAR                                                 !1
         40        SEND_VAR                                                 !4
         41        SEND_VAR                                                 !3
         42        DO_ICALL                                         $19     
         43        SEND_VAR                                                 $19
         44        DO_ICALL                                         $20     
         45        TYPE_CHECK                                  1018          $20
         46      > JMPZ                                                     ~21, ->48
   20    47    > > RETURN                                                   !5
   15    48    >   PRE_INC                                                  !4
         49    >   SUB                                              ~23     !2, !3
         50        IS_SMALLER                                               !4, ~23
         51      > JMPNZ                                                    ~24, ->24
   13    52    >   PRE_DEC                                                  !3
         53    >   IS_SMALLER                                               0, !3
         54      > JMPNZ                                                    ~26, ->22
   24    55    > > RETURN                                                   ''
   25    56*     > RETURN                                                   null

End of function getsimilarsubstring

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.14 ms | 1402 KiB | 22 Q