3v4l.org

run code in 500+ PHP versions simultaneously
<?php $html = <<<HTML <html> <head>...</head> <body> (some js and css) <div class="no_remove">(content)</div> <div class="no_remove">(content that i didn't want to remove) <div class="remove"> <span>(content)</span> <span>(content)</span> <span>(content)</span> <div class="other1">(content)</div> <div class="other2">(content)</div> <div class="other3">(content)</div> </div> </div> </body> </html> HTML; libxml_use_internal_errors(true); $dom=new DOMDocument; $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $xpath = new DOMXPath($dom); foreach($xpath->query('//div[@class="remove"]') as $div) { $div->parentNode->removeChild($div); } echo $dom->saveHTML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 19, Position 2 = 25
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 25
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/jrLJF
function name:  (null)
number of ops:  30
compiled vars:  !0 = $html, !1 = $dom, !2 = $xpath, !3 = $div
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, '%3Chtml%3E%0A%3Chead%3E...%3C%2Fhead%3E%0A%3Cbody%3E%0A%28some+js+and+css%29%0A++++%3Cdiv+class%3D%22no_remove%22%3E%28content%29%3C%2Fdiv%3E%0A++++%3Cdiv+class%3D%22no_remove%22%3E%28content+that+i+didn%27t+want+to+remove%29%0A++++++++%3Cdiv+class%3D%22remove%22%3E%0A++++++++++++%3Cspan%3E%28content%29%3C%2Fspan%3E%0A++++++++++++%3Cspan%3E%28content%29%3C%2Fspan%3E%0A++++++++++++%3Cspan%3E%28content%29%3C%2Fspan%3E%0A++++++++++++%3Cdiv+class%3D%22other1%22%3E%28content%29%3C%2Fdiv%3E%0A++++++++++++%3Cdiv+class%3D%22other2%22%3E%28content%29%3C%2Fdiv%3E%0A++++++++++++%3Cdiv+class%3D%22other3%22%3E%28content%29%3C%2Fdiv%3E%0A++++++++%3C%2Fdiv%3E%0A++++%3C%2Fdiv%3E%0A%3C%2Fbody%3E%0A%3C%2Fhtml%3E'
   22     1        INIT_FCALL                                                   'libxml_use_internal_errors'
          2        SEND_VAL                                                     <true>
          3        DO_ICALL                                                     
   23     4        NEW                                                  $6      'DOMDocument'
          5        DO_FCALL                                          0          
          6        ASSIGN                                                       !1, $6
   24     7        INIT_METHOD_CALL                                             !1, 'loadHTML'
          8        SEND_VAR_EX                                                  !0
          9        SEND_VAL_EX                                                  8196
         10        DO_FCALL                                          0          
   25    11        NEW                                                  $10     'DOMXPath'
         12        SEND_VAR_EX                                                  !1
         13        DO_FCALL                                          0          
         14        ASSIGN                                                       !2, $10
   26    15        INIT_METHOD_CALL                                             !2, 'query'
         16        SEND_VAL_EX                                                  '%2F%2Fdiv%5B%40class%3D%22remove%22%5D'
         17        DO_FCALL                                          0  $13     
         18      > FE_RESET_R                                           $14     $13, ->25
         19    > > FE_FETCH_R                                                   $14, !3, ->25
   27    20    >   FETCH_OBJ_R                                          ~15     !3, 'parentNode'
         21        INIT_METHOD_CALL                                             ~15, 'removeChild'
         22        SEND_VAR_EX                                                  !3
         23        DO_FCALL                                          0          
   26    24      > JMP                                                          ->19
         25    >   FE_FREE                                                      $14
   29    26        INIT_METHOD_CALL                                             !1, 'saveHTML'
         27        DO_FCALL                                          0  $17     
         28        ECHO                                                         $17
         29      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
221.22 ms | 2688 KiB | 14 Q