3v4l.org

run code in 300+ PHP versions simultaneously
<?php $posts['Author1']=['sdsadsad daSDA DDASd asd aSD Sd dA SD ASD sadasdasds sadasd @jhsad.sadas.com sdsdADSA sada', 'KDJKLFFD GFDGFDHGF GFHGFDHGFH GFHFGH Lklfgfd gdfsgfdsg df gfdhgf g hfghghjh jhg @jhsad.sadas.com sfgff fsdfdsf', 'jhjkfsdg fdgdf sfds hgfj j kkjjfghgkjf hdkjtkj lfdjfg hkgfl @jhsad.sadas.com dsfjdshflkds kg lsfdkg;fdgl']; $posts['Author2']=['This is some random string representative of non-signature text. This is the *author\'s* signature.', 'Different message body text. This is the *author\'s* signature. This is an afterthought that expresses that a signature is not always at the end.', 'Finally, this is unwanted stuff. This is the *author\'s* signature.']; foreach($posts as $author=>$texts){ echo "Author: $author\n"; usort($texts,function($a,$b){return strlen($a)-strlen($b);}); // sort ASC by strlen; mb_strlen probably isn't advantageous var_export($texts); echo "\n"; foreach($texts as $index=>$string){ if(!$index){ $overlaps=preg_split('/\s+/',$string,NULL,PREG_SPLIT_NO_EMPTY); // declare with all non-white-space substrings from first text }else{ $overlaps=array_intersect($overlaps,preg_split('/\s+/',$string,NULL,PREG_SPLIT_NO_EMPTY)); // filter word bank using narrowing number of words } } var_export($overlaps); echo "\n"; // batch consecutive substrings $group=null; $consecutives=[]; // clear previous iteration's data foreach($overlaps as $i=>$word){ if($group===null || $i-$last>1){ $group=$i; } $last=$i; $consecutives[$group][]=$word; } var_export($consecutives); echo "\n"; foreach($consecutives as $words){ // match potential signatures in first text for measurement: if(preg_match_all('/\Q'.implode('\E\s+\Q',$words).'\E/',$texts[0],$out)){ // make alternatives characters literal using \Q & \E $potential_signatures=$out[0]; } } usort($potential_signatures,function($a,$b){return strlen($b)-strlen($a);}); // sort DESC by strlen; mb_strlen probably isn't advantageous echo "Assumed Signature: {$potential_signatures[0]}\n\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 102
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 102
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 45
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 45
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 33
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 45
2 jumps found. (Code = 77) Position 1 = 53, Position 2 = 67
Branch analysis from position: 53
2 jumps found. (Code = 78) Position 1 = 54, Position 2 = 67
Branch analysis from position: 54
2 jumps found. (Code = 47) Position 1 = 57, Position 2 = 60
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 61, Position 2 = 62
Branch analysis from position: 61
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
Branch analysis from position: 62
Branch analysis from position: 60
Branch analysis from position: 67
2 jumps found. (Code = 77) Position 1 = 73, Position 2 = 90
Branch analysis from position: 73
2 jumps found. (Code = 78) Position 1 = 74, Position 2 = 90
Branch analysis from position: 74
2 jumps found. (Code = 43) Position 1 = 87, Position 2 = 89
Branch analysis from position: 87
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
Branch analysis from position: 89
Branch analysis from position: 90
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 90
Branch analysis from position: 67
Branch analysis from position: 45
Branch analysis from position: 102
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 102
filename:       /in/AT6pF
function name:  (null)
number of ops:  104
compiled vars:  !0 = $posts, !1 = $texts, !2 = $author, !3 = $string, !4 = $index, !5 = $overlaps, !6 = $group, !7 = $consecutives, !8 = $word, !9 = $i, !10 = $last, !11 = $words, !12 = $out, !13 = $potential_signatures
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN_DIM                                               !0, 'Author1'
          1        OP_DATA                                                  <array>
   10     2        ASSIGN_DIM                                               !0, 'Author2'
          3        OP_DATA                                                  <array>
   21     4      > FE_RESET_R                                       $16     !0, ->102
          5    > > FE_FETCH_R                                       ~17     $16, !1, ->102
          6    >   ASSIGN                                                   !2, ~17
   22     7        ROPE_INIT                                     3  ~20     'Author%3A+'
          8        ROPE_ADD                                      1  ~20     ~20, !2
          9        ROPE_END                                      2  ~19     ~20, '%0A'
         10        ECHO                                                     ~19
   24    11        INIT_FCALL                                               'usort'
         12        SEND_REF                                                 !1
         13        DECLARE_LAMBDA_FUNCTION                          ~22     [0]
         14        SEND_VAL                                                 ~22
         15        DO_ICALL                                                 
   25    16        INIT_FCALL                                               'var_export'
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                                 
   26    19        ECHO                                                     '%0A'
   28    20      > FE_RESET_R                                       $25     !1, ->45
         21    > > FE_FETCH_R                                       ~26     $25, !3, ->45
         22    >   ASSIGN                                                   !4, ~26
   29    23        BOOL_NOT                                         ~28     !4
         24      > JMPZ                                                     ~28, ->33
   30    25    >   INIT_FCALL                                               'preg_split'
         26        SEND_VAL                                                 '%2F%5Cs%2B%2F'
         27        SEND_VAR                                                 !3
         28        SEND_VAL                                                 null
         29        SEND_VAL                                                 1
         30        DO_ICALL                                         $29     
         31        ASSIGN                                                   !5, $29
   29    32      > JMP                                                      ->44
   32    33    >   INIT_FCALL                                               'array_intersect'
         34        SEND_VAR                                                 !5
         35        INIT_FCALL                                               'preg_split'
         36        SEND_VAL                                                 '%2F%5Cs%2B%2F'
         37        SEND_VAR                                                 !3
         38        SEND_VAL                                                 null
         39        SEND_VAL                                                 1
         40        DO_ICALL                                         $31     
         41        SEND_VAR                                                 $31
         42        DO_ICALL                                         $32     
         43        ASSIGN                                                   !5, $32
   28    44    > > JMP                                                      ->21
         45    >   FE_FREE                                                  $25
   35    46        INIT_FCALL                                               'var_export'
         47        SEND_VAR                                                 !5
         48        DO_ICALL                                                 
   36    49        ECHO                                                     '%0A'
   39    50        ASSIGN                                                   !6, null
   40    51        ASSIGN                                                   !7, <array>
   41    52      > FE_RESET_R                                       $37     !5, ->67
         53    > > FE_FETCH_R                                       ~38     $37, !8, ->67
         54    >   ASSIGN                                                   !9, ~38
   42    55        TYPE_CHECK                                    2  ~40     !6
         56      > JMPNZ_EX                                         ~40     ~40, ->60
         57    >   SUB                                              ~41     !9, !10
         58        IS_SMALLER                                       ~42     1, ~41
         59        BOOL                                             ~40     ~42
         60    > > JMPZ                                                     ~40, ->62
   43    61    >   ASSIGN                                                   !6, !9
   45    62    >   ASSIGN                                                   !10, !9
   46    63        FETCH_DIM_W                                      $45     !7, !6
         64        ASSIGN_DIM                                               $45
         65        OP_DATA                                                  !8
   41    66      > JMP                                                      ->53
         67    >   FE_FREE                                                  $37
   48    68        INIT_FCALL                                               'var_export'
         69        SEND_VAR                                                 !7
         70        DO_ICALL                                                 
   49    71        ECHO                                                     '%0A'
   51    72      > FE_RESET_R                                       $48     !7, ->90
         73    > > FE_FETCH_R                                               $48, !11, ->90
   53    74    >   INIT_FCALL                                               'preg_match_all'
         75        INIT_FCALL                                               'implode'
         76        SEND_VAL                                                 '%5CE%5Cs%2B%5CQ'
         77        SEND_VAR                                                 !11
         78        DO_ICALL                                         $49     
         79        CONCAT                                           ~50     '%2F%5CQ', $49
         80        CONCAT                                           ~51     ~50, '%5CE%2F'
         81        SEND_VAL                                                 ~51
         82        FETCH_DIM_R                                      ~52     !1, 0
         83        SEND_VAL                                                 ~52
         84        SEND_REF                                                 !12
         85        DO_ICALL                                         $53     
         86      > JMPZ                                                     $53, ->89
   54    87    >   FETCH_DIM_R                                      ~54     !12, 0
         88        ASSIGN                                                   !13, ~54
   51    89    > > JMP                                                      ->73
         90    >   FE_FREE                                                  $48
   57    91        INIT_FCALL                                               'usort'
         92        SEND_REF                                                 !13
         93        DECLARE_LAMBDA_FUNCTION                          ~56     [1]
         94        SEND_VAL                                                 ~56
         95        DO_ICALL                                                 
   59    96        ROPE_INIT                                     3  ~60     'Assumed+Signature%3A+'
         97        FETCH_DIM_R                                      ~58     !13, 0
         98        ROPE_ADD                                      1  ~60     ~60, ~58
         99        ROPE_END                                      2  ~59     ~60, '%0A%0A'
        100        ECHO                                                     ~59
   21   101      > JMP                                                      ->5
        102    >   FE_FREE                                                  $16
   60   103      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AT6pF
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        STRLEN                                           ~2      !0
          3        STRLEN                                           ~3      !1
          4        SUB                                              ~4      ~2, ~3
          5      > RETURN                                                   ~4
          6*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AT6pF
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        STRLEN                                           ~2      !1
          3        STRLEN                                           ~3      !0
          4        SUB                                              ~4      ~2, ~3
          5      > RETURN                                                   ~4
          6*     > RETURN                                                   null

End of Dynamic Function 1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.1 ms | 1023 KiB | 19 Q