3v4l.org

run code in 300+ PHP versions simultaneously
<?php // INPUT: appl | pinea | orang frui | vege lates // TARGET: +(appl* | pinea* | orang*) +(frui* | vege*) +(lates*) $subject = 'appl | pinea | orang frui | vege lates'; // Add the "*" in place at end $subject = preg_replace('/[a-z]+/i', '$0*', $subject); // Group the terms adding brackets and + sign $result = preg_replace('/(?:[^\s|]+\s*\|\s*)*(?:[^\s|]+)/i', '+($0)', $subject); var_dump($result);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NjIai
function name:  (null)
number of ops:  17
compiled vars:  !0 = $subject, !1 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   ASSIGN                                                   !0, 'appl+%7C+pinea+%7C+orang+frui+%7C+vege+lates'
    9     1        INIT_FCALL                                               'preg_replace'
          2        SEND_VAL                                                 '%2F%5Ba-z%5D%2B%2Fi'
          3        SEND_VAL                                                 '%240%2A'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $3      
          6        ASSIGN                                                   !0, $3
   12     7        INIT_FCALL                                               'preg_replace'
          8        SEND_VAL                                                 '%2F%28%3F%3A%5B%5E%5Cs%7C%5D%2B%5Cs%2A%5C%7C%5Cs%2A%29%2A%28%3F%3A%5B%5E%5Cs%7C%5D%2B%29%2Fi'
          9        SEND_VAL                                                 '%2B%28%240%29'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $5      
         12        ASSIGN                                                   !1, $5
   15    13        INIT_FCALL                                               'var_dump'
         14        SEND_VAR                                                 !1
         15        DO_ICALL                                                 
         16      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.54 ms | 1394 KiB | 17 Q