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 style="color: red">and <p>also</p> this</div> <div style="color: red">and this <div style="color: red">too</div></div> </div> DATA; $dom = new DOMDocument(); $dom->loadHTML($data, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $xpath = new DOMXPath($dom); foreach ($xpath->query("//*[@*]") as $node) { $parent = $node->parentNode; while ($node->hasChildNodes()) { $parent->insertBefore($node->lastChild, $node->nextSibling); } $parent->removeChild($node); } echo $dom->saveHTML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 35
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 35
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 20
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 20
Branch analysis from position: 31
Branch analysis from position: 20
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
filename:       /in/9qHRM
function name:  (null)
number of ops:  40
compiled vars:  !0 = $data, !1 = $dom, !2 = $xpath, !3 = $node, !4 = $parent
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++++%3Cdiv+style%3D%22color%3A+red%22%3Eand+%3Cp%3Ealso%3C%2Fp%3E+this%3C%2Fdiv%3E%0A++++%3Cdiv+style%3D%22color%3A+red%22%3Eand+this+%3Cdiv+style%3D%22color%3A+red%22%3Etoo%3C%2Fdiv%3E%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        SEND_VAL_EX                                              8196
          7        DO_FCALL                                      0          
   16     8        NEW                                              $10     'DOMXPath'
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !2, $10
   18    12        INIT_METHOD_CALL                                         !2, 'query'
         13        SEND_VAL_EX                                              '%2F%2F%2A%5B%40%2A%5D'
         14        DO_FCALL                                      0  $13     
         15      > FE_RESET_R                                       $14     $13, ->35
         16    > > FE_FETCH_R                                               $14, !3, ->35
   19    17    >   FETCH_OBJ_R                                      ~15     !3, 'parentNode'
         18        ASSIGN                                                   !4, ~15
   20    19      > JMP                                                      ->28
   21    20    >   INIT_METHOD_CALL                                         !4, 'insertBefore'
         21        CHECK_FUNC_ARG                                           
         22        FETCH_OBJ_FUNC_ARG                               $17     !3, 'lastChild'
         23        SEND_FUNC_ARG                                            $17
         24        CHECK_FUNC_ARG                                           
         25        FETCH_OBJ_FUNC_ARG                               $18     !3, 'nextSibling'
         26        SEND_FUNC_ARG                                            $18
         27        DO_FCALL                                      0          
   20    28    >   INIT_METHOD_CALL                                         !3, 'hasChildNodes'
         29        DO_FCALL                                      0  $20     
         30      > JMPNZ                                                    $20, ->20
   23    31    >   INIT_METHOD_CALL                                         !4, 'removeChild'
         32        SEND_VAR_EX                                              !3
         33        DO_FCALL                                      0          
   18    34      > JMP                                                      ->16
         35    >   FE_FREE                                                  $14
   26    36        INIT_METHOD_CALL                                         !1, 'saveHTML'
         37        DO_FCALL                                      0  $22     
         38        ECHO                                                     $22
         39      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.71 ms | 1399 KiB | 13 Q