3v4l.org

run code in 300+ PHP versions simultaneously
<?php $text = 'some text [person name="Jackson" family="Smith"] text [vehicle brand="Benz" type="SUV" doors="4" seats="7"] and [invalid closed="false" monkeywrench [lonetag] text [single gender="female"]'; foreach (preg_match_all('~\[(\w+)(?=(?: \w+="\w+")*])(]?)|(?:\G(?!^) (\w+)="(\w+)")~', $text, $out, PREG_SET_ORDER) ? $out : [] as $matches) { if ($matches[2]) { $result[$matches[1]] = []; } elseif (!isset($matches[3])) { $tag = $matches[1]; } else { $result[$tag][$matches[3]] = $matches[4]; } } var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 31
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 31
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 19
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 25
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
Branch analysis from position: 10
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 31
Branch analysis from position: 12
Branch analysis from position: 31
filename:       /in/A13k5
function name:  (null)
number of ops:  36
compiled vars:  !0 = $text, !1 = $out, !2 = $matches, !3 = $result, !4 = $tag
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'some+text+%5Bperson+name%3D%22Jackson%22+family%3D%22Smith%22%5D+text+%5Bvehicle+brand%3D%22Benz%22+type%3D%22SUV%22+doors%3D%224%22+seats%3D%227%22%5D+and+%5Binvalid+closed%3D%22false%22+monkeywrench+%5Blonetag%5D+text+%5Bsingle+gender%3D%22female%22%5D'
    4     1        INIT_FCALL                                               'preg_match_all'
          2        SEND_VAL                                                 '%7E%5C%5B%28%5Cw%2B%29%28%3F%3D%28%3F%3A+%5Cw%2B%3D%22%5Cw%2B%22%29%2A%5D%29%28%5D%3F%29%7C%28%3F%3A%5CG%28%3F%21%5E%29+%28%5Cw%2B%29%3D%22%28%5Cw%2B%29%22%29%7E'
          3        SEND_VAR                                                 !0
          4        SEND_REF                                                 !1
          5        SEND_VAL                                                 2
          6        DO_ICALL                                         $6      
          7      > JMPZ                                                     $6, ->10
          8    >   QM_ASSIGN                                        ~7      !1
          9      > JMP                                                      ->11
         10    >   QM_ASSIGN                                        ~7      <array>
         11    > > FE_RESET_R                                       $8      ~7, ->31
         12    > > FE_FETCH_R                                               $8, !2, ->31
    5    13    >   FETCH_DIM_R                                      ~9      !2, 2
         14      > JMPZ                                                     ~9, ->19
    6    15    >   FETCH_DIM_R                                      ~10     !2, 1
         16        ASSIGN_DIM                                               !3, ~10
         17        OP_DATA                                                  <array>
    5    18      > JMP                                                      ->30
    7    19    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~12     !2, 3
         20        BOOL_NOT                                         ~13     ~12
         21      > JMPZ                                                     ~13, ->25
    8    22    >   FETCH_DIM_R                                      ~14     !2, 1
         23        ASSIGN                                                   !4, ~14
    7    24      > JMP                                                      ->30
   10    25    >   FETCH_DIM_R                                      ~17     !2, 3
         26        FETCH_DIM_R                                      ~19     !2, 4
         27        FETCH_DIM_W                                      $16     !3, !4
         28        ASSIGN_DIM                                               $16, ~17
         29        OP_DATA                                                  ~19
    4    30    > > JMP                                                      ->12
         31    >   FE_FREE                                                  $8
   14    32        INIT_FCALL                                               'var_export'
         33        SEND_VAR                                                 !3
         34        DO_ICALL                                                 
         35      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.27 ms | 1004 KiB | 15 Q