3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = 'Love in My Antonia Love in'; preg_match_all('~(\b\w++(?> \w++)*)(?=.*?\b\1)~i', $str, $matches); // Remove duplicate found values from matches $array = array_unique(array_map('strtolower', $matches[1])); foreach ($array as $value) { // Remove found phrase / word from the end $str = preg_replace("~^.*\K(?<!\s)\s*\b$value~i", '', $str); } echo trim($str); // Love in My Antonia
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 27
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 27
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/phAtO
function name:  (null)
number of ops:  33
compiled vars:  !0 = $str, !1 = $matches, !2 = $array, !3 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'Love+in+My+Antonia+Love+in'
    4     1        INIT_FCALL                                               'preg_match_all'
          2        SEND_VAL                                                 '%7E%28%5Cb%5Cw%2B%2B%28%3F%3E+%5Cw%2B%2B%29%2A%29%28%3F%3D.%2A%3F%5Cb%5C1%29%7Ei'
          3        SEND_VAR                                                 !0
          4        SEND_REF                                                 !1
          5        DO_ICALL                                                 
    6     6        INIT_FCALL                                               'array_unique'
          7        INIT_FCALL                                               'array_map'
          8        SEND_VAL                                                 'strtolower'
          9        FETCH_DIM_R                                      ~6      !1, 1
         10        SEND_VAL                                                 ~6
         11        DO_ICALL                                         $7      
         12        SEND_VAR                                                 $7
         13        DO_ICALL                                         $8      
         14        ASSIGN                                                   !2, $8
    7    15      > FE_RESET_R                                       $10     !2, ->27
         16    > > FE_FETCH_R                                               $10, !3, ->27
    9    17    >   INIT_FCALL                                               'preg_replace'
         18        ROPE_INIT                                     3  ~12     '%7E%5E.%2A%5CK%28%3F%3C%21%5Cs%29%5Cs%2A%5Cb'
         19        ROPE_ADD                                      1  ~12     ~12, !3
         20        ROPE_END                                      2  ~11     ~12, '%7Ei'
         21        SEND_VAL                                                 ~11
         22        SEND_VAL                                                 ''
         23        SEND_VAR                                                 !0
         24        DO_ICALL                                         $14     
         25        ASSIGN                                                   !0, $14
    7    26      > JMP                                                      ->16
         27    >   FE_FREE                                                  $10
   11    28        INIT_FCALL                                               'trim'
         29        SEND_VAR                                                 !0
         30        DO_ICALL                                         $16     
         31        ECHO                                                     $16
         32      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.3 ms | 1010 KiB | 18 Q