3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = <<<DATA <div> <p>These line shall stay</p> <p class="myclass">Remove this one</p> <p>But keep this</p> <div style="color: red">and this</div> </div> DATA; $dom = new DOMDOcument(); $dom->loadHTML($data, LIBXML_HTML_NOIMPLIED); $xpath = new DOMXPath($dom); $lines_to_be_removed = $xpath->query("//*[count(@*)>0]"); foreach ($lines_to_be_removed as $line) { $line->parentNode->removeChild($line); } // just to check echo $dom->saveHtml($dom->documentElement); ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 23
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 23
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/DA1bJ
function name:  (null)
number of ops:  31
compiled vars:  !0 = $data, !1 = $dom, !2 = $xpath, !3 = $lines_to_be_removed, !4 = $line
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Cdiv%3E%0A++++%3Cp%3EThese+line+shall+stay%3C%2Fp%3E%0A++++%3Cp+class%3D%22myclass%22%3ERemove+this+one%3C%2Fp%3E%0A++++%3Cp%3EBut+keep+this%3C%2Fp%3E%0A++++%3Cdiv+style%3D%22color%3A+red%22%3Eand+this%3C%2Fdiv%3E%0A%3C%2Fdiv%3E'
   12     1        NEW                                              $6      'DOMDOcument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $6
   13     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        SEND_VAL_EX                                              8192
          7        DO_FCALL                                      0          
   15     8        NEW                                              $10     'DOMXPath'
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !2, $10
   17    12        INIT_METHOD_CALL                                         !2, 'query'
         13        SEND_VAL_EX                                              '%2F%2F%2A%5Bcount%28%40%2A%29%3E0%5D'
         14        DO_FCALL                                      0  $13     
         15        ASSIGN                                                   !3, $13
   19    16      > FE_RESET_R                                       $15     !3, ->23
         17    > > FE_FETCH_R                                               $15, !4, ->23
   20    18    >   FETCH_OBJ_R                                      ~16     !4, 'parentNode'
         19        INIT_METHOD_CALL                                         ~16, 'removeChild'
         20        SEND_VAR_EX                                              !4
         21        DO_FCALL                                      0          
   19    22      > JMP                                                      ->17
         23    >   FE_FREE                                                  $15
   24    24        INIT_METHOD_CALL                                         !1, 'saveHtml'
         25        CHECK_FUNC_ARG                                           
         26        FETCH_OBJ_FUNC_ARG                               $18     !1, 'documentElement'
         27        SEND_FUNC_ARG                                            $18
         28        DO_FCALL                                      0  $19     
         29        ECHO                                                     $19
   25    30      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.85 ms | 1395 KiB | 13 Q