3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <h2>My title 1</h2> <h3>Sub-heading</h3> <p>...<span><a href='#'>...</a></span></p> <div>...</div> <h2>My title 2</h2> <p>No sub-heading here :O</p> <h3>But here</h3> <p>No link</p> <h2>And so on...</h2> <p>...</p> <div><h2>This is nested</h2></div> HTML; $doc = new DOMDocument(); $doc->loadHTML($html); $xpath = new DOMXpath($doc); $domNodeList = $xpath->query('/html/body/h2'); $sets = array(); foreach($domNodeList as $element) { // Save the h2 $set = array($element); // Loop the siblings unit the next h2 while ($element = $element->nextSibling) { if ($element->nodeName === "h2") { break; } // if Node is a DOMElement if ($element->nodeType === 1) { $set[] = $element; } } $sets[] = $set; } var_dump($sets);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 36
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 36
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 21
Branch analysis from position: 33
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 = 33
Branch analysis from position: 33
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 30
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 21
Branch analysis from position: 33
Branch analysis from position: 21
Branch analysis from position: 30
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
filename:       /in/sX0Rr
function name:  (null)
number of ops:  41
compiled vars:  !0 = $html, !1 = $doc, !2 = $xpath, !3 = $domNodeList, !4 = $sets, !5 = $element, !6 = $set
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%3Ch2%3EMy+title+1%3C%2Fh2%3E%0A%3Ch3%3ESub-heading%3C%2Fh3%3E%0A%3Cp%3E...%3Cspan%3E%3Ca+href%3D%27%23%27%3E...%3C%2Fa%3E%3C%2Fspan%3E%3C%2Fp%3E%0A%3Cdiv%3E...%3C%2Fdiv%3E%0A%3Ch2%3EMy+title+2%3C%2Fh2%3E%0A%3Cp%3ENo+sub-heading+here+%3AO%3C%2Fp%3E%0A%3Ch3%3EBut+here%3C%2Fh3%3E%0A%3Cp%3ENo+link%3C%2Fp%3E%0A%3Ch2%3EAnd+so+on...%3C%2Fh2%3E%0A%3Cp%3E...%3C%2Fp%3E%0A%3Cdiv%3E%3Ch2%3EThis+is+nested%3C%2Fh2%3E%3C%2Fdiv%3E'
   16     1        NEW                                              $8      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $8
   17     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   18     7        NEW                                              $12     'DOMXpath'
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !2, $12
   19    11        INIT_METHOD_CALL                                         !2, 'query'
         12        SEND_VAL_EX                                              '%2Fhtml%2Fbody%2Fh2'
         13        DO_FCALL                                      0  $15     
         14        ASSIGN                                                   !3, $15
   21    15        ASSIGN                                                   !4, <array>
   23    16      > FE_RESET_R                                       $18     !3, ->36
         17    > > FE_FETCH_R                                               $18, !5, ->36
   25    18    >   INIT_ARRAY                                       ~19     !5
         19        ASSIGN                                                   !6, ~19
   28    20      > JMP                                                      ->30
   29    21    >   FETCH_OBJ_R                                      ~21     !5, 'nodeName'
         22        IS_IDENTICAL                                             ~21, 'h2'
         23      > JMPZ                                                     ~22, ->25
   30    24    > > JMP                                                      ->33
   33    25    >   FETCH_OBJ_R                                      ~23     !5, 'nodeType'
         26        IS_IDENTICAL                                             ~23, 1
         27      > JMPZ                                                     ~24, ->30
   34    28    >   ASSIGN_DIM                                               !6
         29        OP_DATA                                                  !5
   28    30    >   FETCH_OBJ_R                                      ~26     !5, 'nextSibling'
         31        ASSIGN                                           ~27     !5, ~26
         32      > JMPNZ                                                    ~27, ->21
   38    33    >   ASSIGN_DIM                                               !4
         34        OP_DATA                                                  !6
   23    35      > JMP                                                      ->17
         36    >   FE_FREE                                                  $18
   41    37        INIT_FCALL                                               'var_dump'
         38        SEND_VAR                                                 !4
         39        DO_ICALL                                                 
         40      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.82 ms | 1400 KiB | 15 Q