3v4l.org

run code in 500+ PHP versions simultaneously
<?php $html = ' <div class="temp"> [title type="text" tag="h2" value="This is my cool title" disabled some-attribute] [text type="text" tag="p" value="Lorem ipsum dolor sit amet"] </div> '; preg_match_all('/\[(.*?)\]/', $html, $matches); $result = []; foreach ($matches[1] as $match) { $id = strtok($match, ' '); $tag = ['id' => $id]; while ($token = strtok(' ')) { if (str_contains($token, '=')) { [$key, $value] = explode('=', $token); if (str_ends_with($token, '"')) { $tag[$key] = trim($value, '"'); continue; } $value2 = strtok('"'); $tag[$key] = trim("$value $value2", '"'); continue; } $tag[$token] = true; } $result[] = $tag; } print_r($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 59
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 59
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
2 jumps found. (Code = 44) Position 1 = 56, Position 2 = 18
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 49
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 38
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
Branch analysis from position: 49
2 jumps found. (Code = 44) Position 1 = 56, Position 2 = 18
Branch analysis from position: 56
Branch analysis from position: 18
Branch analysis from position: 59
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 59
filename:       /in/1ThIF
function name:  (null)
number of ops:  64
compiled vars:  !0 = $html, !1 = $matches, !2 = $result, !3 = $match, !4 = $id, !5 = $tag, !6 = $token, !7 = $key, !8 = $value, !9 = $value2
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '%0A%3Cdiv+class%3D%22temp%22%3E%0A++++%5Btitle+type%3D%22text%22+tag%3D%22h2%22+value%3D%22This+is+my+cool+title%22+disabled+some-attribute%5D%0A++++%5Btext+type%3D%22text%22+tag%3D%22p%22+value%3D%22Lorem+ipsum+dolor+sit+amet%22%5D%0A%3C%2Fdiv%3E%0A'
   10     1        INIT_FCALL                                                   'preg_match_all'
          2        SEND_VAL                                                     '%2F%5C%5B%28.%2A%3F%29%5C%5D%2F'
          3        SEND_VAR                                                     !0
          4        SEND_REF                                                     !1
          5        DO_ICALL                                                     
   11     6        ASSIGN                                                       !2, <array>
   13     7        FETCH_DIM_R                                          ~13     !1, 1
          8      > FE_RESET_R                                           $14     ~13, ->59
          9    > > FE_FETCH_R                                                   $14, !3, ->59
   14    10    >   INIT_FCALL                                                   'strtok'
         11        SEND_VAR                                                     !3
         12        SEND_VAL                                                     '+'
         13        DO_ICALL                                             $15     
         14        ASSIGN                                                       !4, $15
   15    15        INIT_ARRAY                                           ~17     !4, 'id'
         16        ASSIGN                                                       !5, ~17
   16    17      > JMP                                                          ->51
   17    18    >   FRAMELESS_ICALL_2                str_contains        ~19     !6, '%3D'
         19      > JMPZ                                                         ~19, ->49
   18    20    >   INIT_FCALL                                                   'explode'
         21        SEND_VAL                                                     '%3D'
         22        SEND_VAR                                                     !6
         23        DO_ICALL                                             $20     
         24        FETCH_LIST_R                                         $21     $20, 0
         25        ASSIGN                                                       !7, $21
         26        FETCH_LIST_R                                         $23     $20, 1
         27        ASSIGN                                                       !8, $23
         28        FREE                                                         $20
   19    29        INIT_FCALL                                                   'str_ends_with'
         30        SEND_VAR                                                     !6
         31        SEND_VAL                                                     '%22'
         32        DO_ICALL                                             $25     
         33      > JMPZ                                                         $25, ->38
   20    34    >   FRAMELESS_ICALL_2                trim                ~27     !8, '%22'
         35        ASSIGN_DIM                                                   !5, !7
         36        OP_DATA                                                      ~27
   21    37      > JMP                                                          ->51
   23    38    >   INIT_FCALL                                                   'strtok'
         39        SEND_VAL                                                     '%22'
         40        DO_ICALL                                             $28     
         41        ASSIGN                                                       !9, $28
   24    42        ROPE_INIT                                         3  ~32     !8
         43        ROPE_ADD                                          1  ~32     ~32, '+'
         44        ROPE_END                                          2  ~31     ~32, !9
         45        FRAMELESS_ICALL_2                trim                ~34     ~31, '%22'
         46        ASSIGN_DIM                                                   !5, !7
         47        OP_DATA                                                      ~34
   25    48      > JMP                                                          ->51
   27    49    >   ASSIGN_DIM                                                   !5, !6
         50        OP_DATA                                                      <true>
   16    51    >   INIT_FCALL                                                   'strtok'
         52        SEND_VAL                                                     '+'
         53        DO_ICALL                                             $36     
         54        ASSIGN                                               ~37     !6, $36
         55      > JMPNZ                                                        ~37, ->18
   30    56    >   ASSIGN_DIM                                                   !2
         57        OP_DATA                                                      !5
   13    58      > JMP                                                          ->9
         59    >   FE_FREE                                                      $14
   33    60        INIT_FCALL                                                   'print_r'
         61        SEND_VAR                                                     !2
         62        DO_ICALL                                                     
         63      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
146.58 ms | 1779 KiB | 18 Q