3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<TAG <h1>This is my title</h1> <p>This is a text right under my h1 title.</p> <p>This is some more text under my h1 title</p> <h2>This is my level 2 heading</h2> <p>This is text right under my level 2 heading</p> <h3>First h3</h3> <p>First paragraph for the first h3</p> <h3>Second h3</h3> <p>First paragraph for the second h3</p> <h3>Third h3</h3> <p>First paragraph for the third h3</p> <p>Second paragraph for the third h3</p> <h2>This is my level 2 heading</h2> <p>This is text right under my level 2 heading</p> TAG; $dom = new DomDocument(); // Load the HTML, don't worry about it being a fragment $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $xpath = new DOMXPath($dom); // Grab all H3 tags. This might need to be adjusted if there's more to the depth $results = $xpath->query("//h3"); foreach ($results as $result) { var_dump(sprintf('<h3>%1$s</h3>', $result->textContent)); // See if the next element is a P tag $next = $result->nextElementSibling; if ($next && 'p' === $next->nodeName) { var_dump(sprintf('<p>%1$s</p>', $next->textContent)); } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 42
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 42
Branch analysis from position: 18
2 jumps found. (Code = 46) Position 1 = 29, Position 2 = 32
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 41
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 41
Branch analysis from position: 32
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
filename:       /in/gvBrv
function name:  (null)
number of ops:  44
compiled vars:  !0 = $html, !1 = $dom, !2 = $xpath, !3 = $results, !4 = $result, !5 = $next
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Ch1%3EThis+is+my+title%3C%2Fh1%3E%0A%0A%3Cp%3EThis+is+a+text+right+under+my+h1+title.%3C%2Fp%3E%0A%3Cp%3EThis+is+some+more+text+under+my+h1+title%3C%2Fp%3E%0A%0A%3Ch2%3EThis+is+my+level+2+heading%3C%2Fh2%3E%0A%3Cp%3EThis+is+text+right+under+my+level+2+heading%3C%2Fp%3E%0A%0A%3Ch3%3EFirst+h3%3C%2Fh3%3E%0A%3Cp%3EFirst+paragraph+for+the+first+h3%3C%2Fp%3E%0A%0A%3Ch3%3ESecond+h3%3C%2Fh3%3E%0A%3Cp%3EFirst+paragraph+for+the+second+h3%3C%2Fp%3E%0A%0A%3Ch3%3EThird+h3%3C%2Fh3%3E%0A%3Cp%3EFirst+paragraph+for+the+third+h3%3C%2Fp%3E%0A%3Cp%3ESecond+paragraph+for+the+third+h3%3C%2Fp%3E%0A%0A%3Ch2%3EThis+is+my+level+2+heading%3C%2Fh2%3E%0A%3Cp%3EThis+is+text+right+under+my+level+2+heading%3C%2Fp%3E'
   27     1        NEW                                              $7      'DomDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $7
   29     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        SEND_VAL_EX                                              8196
          7        DO_FCALL                                      0          
   31     8        NEW                                              $11     'DOMXPath'
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !2, $11
   34    12        INIT_METHOD_CALL                                         !2, 'query'
         13        SEND_VAL_EX                                              '%2F%2Fh3'
         14        DO_FCALL                                      0  $14     
         15        ASSIGN                                                   !3, $14
   35    16      > FE_RESET_R                                       $16     !3, ->42
         17    > > FE_FETCH_R                                               $16, !4, ->42
   36    18    >   INIT_FCALL                                               'var_dump'
         19        INIT_FCALL                                               'sprintf'
         20        SEND_VAL                                                 '%3Ch3%3E%251%24s%3C%2Fh3%3E'
         21        FETCH_OBJ_R                                      ~17     !4, 'textContent'
         22        SEND_VAL                                                 ~17
         23        DO_ICALL                                         $18     
         24        SEND_VAR                                                 $18
         25        DO_ICALL                                                 
   39    26        FETCH_OBJ_R                                      ~20     !4, 'nextElementSibling'
         27        ASSIGN                                                   !5, ~20
   40    28      > JMPZ_EX                                          ~22     !5, ->32
         29    >   FETCH_OBJ_R                                      ~23     !5, 'nodeName'
         30        IS_IDENTICAL                                     ~24     ~23, 'p'
         31        BOOL                                             ~22     ~24
         32    > > JMPZ                                                     ~22, ->41
   41    33    >   INIT_FCALL                                               'var_dump'
         34        INIT_FCALL                                               'sprintf'
         35        SEND_VAL                                                 '%3Cp%3E%251%24s%3C%2Fp%3E'
         36        FETCH_OBJ_R                                      ~25     !5, 'textContent'
         37        SEND_VAL                                                 ~25
         38        DO_ICALL                                         $26     
         39        SEND_VAR                                                 $26
         40        DO_ICALL                                                 
   35    41    > > JMP                                                      ->17
         42    >   FE_FREE                                                  $16
   43    43      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.12 ms | 1008 KiB | 15 Q