3v4l.org

run code in 300+ 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 = 68
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 68
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 60
Branch analysis from position: 60
2 jumps found. (Code = 44) Position 1 = 65, Position 2 = 18
Branch analysis from position: 65
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 = 23, Position 2 = 58
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 44
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 60
Branch analysis from position: 60
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 60
Branch analysis from position: 60
Branch analysis from position: 58
2 jumps found. (Code = 44) Position 1 = 65, Position 2 = 18
Branch analysis from position: 65
Branch analysis from position: 18
Branch analysis from position: 68
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 68
filename:       /in/1ThIF
function name:  (null)
number of ops:  73
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, ->68
          9    > > FE_FETCH_R                                               $14, !3, ->68
   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                                                      ->60
   17    18    >   INIT_FCALL                                               'str_contains'
         19        SEND_VAR                                                 !6
         20        SEND_VAL                                                 '%3D'
         21        DO_ICALL                                         $19     
         22      > JMPZ                                                     $19, ->58
   18    23    >   INIT_FCALL                                               'explode'
         24        SEND_VAL                                                 '%3D'
         25        SEND_VAR                                                 !6
         26        DO_ICALL                                         $20     
         27        FETCH_LIST_R                                     $21     $20, 0
         28        ASSIGN                                                   !7, $21
         29        FETCH_LIST_R                                     $23     $20, 1
         30        ASSIGN                                                   !8, $23
         31        FREE                                                     $20
   19    32        INIT_FCALL                                               'str_ends_with'
         33        SEND_VAR                                                 !6
         34        SEND_VAL                                                 '%22'
         35        DO_ICALL                                         $25     
         36      > JMPZ                                                     $25, ->44
   20    37    >   INIT_FCALL                                               'trim'
         38        SEND_VAR                                                 !8
         39        SEND_VAL                                                 '%22'
         40        DO_ICALL                                         $27     
         41        ASSIGN_DIM                                               !5, !7
         42        OP_DATA                                                  $27
   21    43      > JMP                                                      ->60
   23    44    >   INIT_FCALL                                               'strtok'
         45        SEND_VAL                                                 '%22'
         46        DO_ICALL                                         $28     
         47        ASSIGN                                                   !9, $28
   24    48        INIT_FCALL                                               'trim'
         49        ROPE_INIT                                     3  ~32     !8
         50        ROPE_ADD                                      1  ~32     ~32, '+'
         51        ROPE_END                                      2  ~31     ~32, !9
         52        SEND_VAL                                                 ~31
         53        SEND_VAL                                                 '%22'
         54        DO_ICALL                                         $34     
         55        ASSIGN_DIM                                               !5, !7
         56        OP_DATA                                                  $34
   25    57      > JMP                                                      ->60
   27    58    >   ASSIGN_DIM                                               !5, !6
         59        OP_DATA                                                  <true>
   16    60    >   INIT_FCALL                                               'strtok'
         61        SEND_VAL                                                 '+'
         62        DO_ICALL                                         $36     
         63        ASSIGN                                           ~37     !6, $36
         64      > JMPNZ                                                    ~37, ->18
   30    65    >   ASSIGN_DIM                                               !2
         66        OP_DATA                                                  !5
   13    67      > JMP                                                      ->9
         68    >   FE_FREE                                                  $14
   33    69        INIT_FCALL                                               'print_r'
         70        SEND_VAR                                                 !2
         71        DO_ICALL                                                 
         72      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
218.71 ms | 1025 KiB | 20 Q