3v4l.org

run code in 500+ PHP versions simultaneously
<?php $data = <<<DATA <div> <p>سلام</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(mb_convert_encoding($data, 'HTML-ENTITIES', 'UTF-8'), 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($dom->documentElement);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 40
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 40
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 25
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 25
Branch analysis from position: 36
Branch analysis from position: 25
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
filename:       /in/A3Ck1
function name:  (null)
number of ops:  48
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%3E%D8%B3%D9%84%D8%A7%D9%85%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        INIT_FCALL                                                   'mb_convert_encoding'
          6        SEND_VAR                                                     !0
          7        SEND_VAL                                                     'HTML-ENTITIES'
          8        SEND_VAL                                                     'UTF-8'
          9        DO_ICALL                                             $9      
         10        SEND_VAR_NO_REF_EX                                           $9
         11        SEND_VAL_EX                                                  8196
         12        DO_FCALL                                          0          
   16    13        NEW                                                  $11     'DOMXPath'
         14        SEND_VAR_EX                                                  !1
         15        DO_FCALL                                          0          
         16        ASSIGN                                                       !2, $11
   18    17        INIT_METHOD_CALL                                             !2, 'query'
         18        SEND_VAL_EX                                                  '%2F%2F%2A%5B%40%2A%5D'
         19        DO_FCALL                                          0  $14     
         20      > FE_RESET_R                                           $15     $14, ->40
         21    > > FE_FETCH_R                                                   $15, !3, ->40
   19    22    >   FETCH_OBJ_R                                          ~16     !3, 'parentNode'
         23        ASSIGN                                                       !4, ~16
   20    24      > JMP                                                          ->33
   21    25    >   INIT_METHOD_CALL                                             !4, 'insertBefore'
         26        CHECK_FUNC_ARG                                               
         27        FETCH_OBJ_FUNC_ARG                                   $18     !3, 'lastChild'
         28        SEND_FUNC_ARG                                                $18
         29        CHECK_FUNC_ARG                                               
         30        FETCH_OBJ_FUNC_ARG                                   $19     !3, 'nextSibling'
         31        SEND_FUNC_ARG                                                $19
         32        DO_FCALL                                          0          
   20    33    >   INIT_METHOD_CALL                                             !3, 'hasChildNodes'
         34        DO_FCALL                                          0  $21     
         35      > JMPNZ                                                        $21, ->25
   23    36    >   INIT_METHOD_CALL                                             !4, 'removeChild'
         37        SEND_VAR_EX                                                  !3
         38        DO_FCALL                                          0          
   18    39      > JMP                                                          ->21
         40    >   FE_FREE                                                      $15
   26    41        INIT_METHOD_CALL                                             !1, 'saveHTML'
         42        CHECK_FUNC_ARG                                               
         43        FETCH_OBJ_FUNC_ARG                                   $23     !1, 'documentElement'
         44        SEND_FUNC_ARG                                                $23
         45        DO_FCALL                                          0  $24     
         46        ECHO                                                         $24
         47      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
205.75 ms | 2328 KiB | 14 Q