3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = '<h1>Title 1</h1> <div class="items">some data and divs here 1</div> <h1>Title 2</h1> <div class="items">some data and divs here 2</div> <div class="items">some data and divs here 3</div> <h1>Title 3</h1> <div class="items">some data and divs here 4</div> <div class="items">some data and divs here 5</div> <div class="items">some data and divs here 6</div>'; $doc = new DOMDocument(); $doc->loadHTML($html); $xpath = new DOMXpath($doc); $domNodeList = $xpath->query('/html/body/h1'); $result = []; foreach($domNodeList as $element) { // Save the h1 $item = $element->nodeValue; // Loop the siblings unit the next h1 while ($element = $element->nextSibling) { if ($element->nodeName === "h1") { break; } // if Node is a DOMElement if ($element->nodeType === 1) { $result[] = ['item' => $item, 'data' => $element->nodeValue]; } } } var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 37
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 37
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 21
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 25
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 33
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 21
Branch analysis from position: 36
Branch analysis from position: 21
Branch analysis from position: 33
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
filename:       /in/FaaSS
function name:  (null)
number of ops:  42
compiled vars:  !0 = $html, !1 = $doc, !2 = $xpath, !3 = $domNodeList, !4 = $result, !5 = $element, !6 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Ch1%3ETitle+1%3C%2Fh1%3E%0A%3Cdiv+class%3D%22items%22%3Esome+data+and+divs+here+1%3C%2Fdiv%3E%0A%3Ch1%3ETitle+2%3C%2Fh1%3E%0A%3Cdiv+class%3D%22items%22%3Esome+data+and+divs+here+2%3C%2Fdiv%3E%0A%3Cdiv+class%3D%22items%22%3Esome+data+and+divs+here+3%3C%2Fdiv%3E%0A%3Ch1%3ETitle+3%3C%2Fh1%3E%0A%3Cdiv+class%3D%22items%22%3Esome+data+and+divs+here+4%3C%2Fdiv%3E%0A%3Cdiv+class%3D%22items%22%3Esome+data+and+divs+here+5%3C%2Fdiv%3E%0A%3Cdiv+class%3D%22items%22%3Esome+data+and+divs+here+6%3C%2Fdiv%3E'
   13     1        NEW                                              $8      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $8
   14     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   15     7        NEW                                              $12     'DOMXpath'
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !2, $12
   16    11        INIT_METHOD_CALL                                         !2, 'query'
         12        SEND_VAL_EX                                              '%2Fhtml%2Fbody%2Fh1'
         13        DO_FCALL                                      0  $15     
         14        ASSIGN                                                   !3, $15
   18    15        ASSIGN                                                   !4, <array>
   19    16      > FE_RESET_R                                       $18     !3, ->37
         17    > > FE_FETCH_R                                               $18, !5, ->37
   21    18    >   FETCH_OBJ_R                                      ~19     !5, 'nodeValue'
         19        ASSIGN                                                   !6, ~19
   24    20      > JMP                                                      ->33
   25    21    >   FETCH_OBJ_R                                      ~21     !5, 'nodeName'
         22        IS_IDENTICAL                                             ~21, 'h1'
         23      > JMPZ                                                     ~22, ->25
   26    24    > > JMP                                                      ->36
   29    25    >   FETCH_OBJ_R                                      ~23     !5, 'nodeType'
         26        IS_IDENTICAL                                             ~23, 1
         27      > JMPZ                                                     ~24, ->33
   30    28    >   INIT_ARRAY                                       ~26     !6, 'item'
         29        FETCH_OBJ_R                                      ~27     !5, 'nodeValue'
         30        ADD_ARRAY_ELEMENT                                ~26     ~27, 'data'
         31        ASSIGN_DIM                                               !4
         32        OP_DATA                                                  ~26
   24    33    >   FETCH_OBJ_R                                      ~28     !5, 'nextSibling'
         34        ASSIGN                                           ~29     !5, ~28
         35      > JMPNZ                                                    ~29, ->21
   19    36    > > JMP                                                      ->17
         37    >   FE_FREE                                                  $18
   34    38        INIT_FCALL                                               'var_export'
         39        SEND_VAR                                                 !4
         40        DO_ICALL                                                 
         41      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
188.01 ms | 1002 KiB | 14 Q