3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = 'Hello how [t- are] you [k- today], Sir?'; $types = ['' => 'normal', 't' => 'target', 'k' => 'key']; if ( preg_match_all('~ (?| \[ (?<type>[^]-]+) - \h (?<content>[^]]+) ] | () ([^[]+) ) ~x', $str, $matches, PREG_SET_ORDER) ) { foreach ($matches as &$m) { unset($m[0], $m[1], $m[2]); $m['type'] = $types[$m['type']]; } print_r($matches); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 23
Branch analysis from position: 9
2 jumps found. (Code = 125) Position 1 = 10, Position 2 = 19
Branch analysis from position: 10
2 jumps found. (Code = 126) Position 1 = 11, Position 2 = 19
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
Branch analysis from position: 23
filename:       /in/A1orX
function name:  (null)
number of ops:  24
compiled vars:  !0 = $str, !1 = $types, !2 = $matches, !3 = $m
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'Hello+how+%5Bt-+are%5D+you+%5Bk-+today%5D%2C+Sir%3F'
    5     1        ASSIGN                                                   !1, <array>
    7     2        INIT_FCALL                                               'preg_match_all'
          3        SEND_VAL                                                 '%7E+%28%3F%7C+%5C%5B+%28%3F%3Ctype%3E%5B%5E%5D-%5D%2B%29+-+%5Ch+%28%3F%3Ccontent%3E%5B%5E%5D%5D%2B%29+%5D+%7C+%28%29+%28%5B%5E%5B%5D%2B%29+%29+%7Ex'
          4        SEND_VAR                                                 !0
          5        SEND_REF                                                 !2
          6        SEND_VAL                                                 2
          7        DO_ICALL                                         $6      
          8      > JMPZ                                                     $6, ->23
    8     9    > > FE_RESET_RW                                      $7      !2, ->19
         10    > > FE_FETCH_RW                                              $7, !3, ->19
    9    11    >   UNSET_DIM                                                !3, 0
         12        UNSET_DIM                                                !3, 1
         13        UNSET_DIM                                                !3, 2
   10    14        FETCH_DIM_R                                      ~9      !3, 'type'
         15        FETCH_DIM_R                                      ~10     !1, ~9
         16        ASSIGN_DIM                                               !3, 'type'
         17        OP_DATA                                                  ~10
    8    18      > JMP                                                      ->10
         19    >   FE_FREE                                                  $7
   12    20        INIT_FCALL                                               'print_r'
         21        SEND_VAR                                                 !2
         22        DO_ICALL                                                 
   13    23    > > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
231.79 ms | 1011 KiB | 15 Q