3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<'HTML' <div class="wrapper"> <h2>This is a header</h2> <h2>This is one too</h2> <h4>Here's one</h4> <div class="ignore"> <h5>I'm one in here too</h5> </div> </div> HTML; $dom = new DOMDocument; $dom->loadHTML($html); $xp = new DOMXPath($dom); $nodeList = $xp->query(' //* [contains(";h1;h2;h3;h4;h5;h6;", concat(";", local-name(), ";"))] [not(ancestor::div[ contains(concat(" ", normalize-space(@class), " "), " ignore ") ]) ]'); foreach ($nodeList as $node) { echo 'tag name: ', $node->nodeName, PHP_EOL, 'html content: ', $dom->saveHTML($node), PHP_EOL, 'text content: ', $node->textContent, PHP_EOL, PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 33
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 33
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/pdjNd
function name:  (null)
number of ops:  35
compiled vars:  !0 = $html, !1 = $dom, !2 = $xp, !3 = $nodeList, !4 = $node
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Cdiv+class%3D%22wrapper%22%3E%0A%3Ch2%3EThis+is+a+header%3C%2Fh2%3E%0A%3Ch2%3EThis+is+one+too%3C%2Fh2%3E%0A%3Ch4%3EHere%27s+one%3C%2Fh4%3E%0A%3Cdiv+class%3D%22ignore%22%3E%0A%3Ch5%3EI%27m+one+in+here+too%3C%2Fh5%3E%0A%3C%2Fdiv%3E%0A%3C%2Fdiv%3E'
   14     1        NEW                                              $6      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $6
   15     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   16     7        NEW                                              $10     'DOMXPath'
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !2, $10
   18    11        INIT_METHOD_CALL                                         !2, 'query'
         12        SEND_VAL_EX                                              '%0A%2F%2F%2A%0A%5Bcontains%28%22%3Bh1%3Bh2%3Bh3%3Bh4%3Bh5%3Bh6%3B%22%2C+concat%28%22%3B%22%2C+local-name%28%29%2C+%22%3B%22%29%29%5D%0A%5Bnot%28ancestor%3A%3Adiv%5B%0A++++contains%28concat%28%22+%22%2C+normalize-space%28%40class%29%2C+%22+%22%29%2C+%22+ignore+%22%29%0A++++%5D%29%0A%5D'
         13        DO_FCALL                                      0  $13     
         14        ASSIGN                                                   !3, $13
   26    15      > FE_RESET_R                                       $15     !3, ->33
         16    > > FE_FETCH_R                                               $15, !4, ->33
   27    17    >   ECHO                                                     'tag+name%3A+'
         18        FETCH_OBJ_R                                      ~16     !4, 'nodeName'
         19        ECHO                                                     ~16
         20        ECHO                                                     '%0A'
   28    21        ECHO                                                     'html+content%3A+'
         22        INIT_METHOD_CALL                                         !1, 'saveHTML'
         23        SEND_VAR_EX                                              !4
         24        DO_FCALL                                      0  $17     
         25        ECHO                                                     $17
         26        ECHO                                                     '%0A'
   29    27        ECHO                                                     'text+content%3A+'
         28        FETCH_OBJ_R                                      ~18     !4, 'textContent'
         29        ECHO                                                     ~18
         30        ECHO                                                     '%0A'
   30    31        ECHO                                                     '%0A'
   26    32      > JMP                                                      ->16
         33    >   FE_FREE                                                  $15
   31    34      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
345.98 ms | 1012 KiB | 13 Q