3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html_string = <<<STR <p>paragraph <a>link</a> </p> <div class="myclass"> <div>something</div> <div style="mystyle">something</div> <b><a href="#">link</a></b> <b><a href="#" name="a name">link</a></b> <b style="color:red">bold</b> <img src="../path" alt="something" /> <img src="../path" alt="something" class="myclass" /> </div> STR; $dom = new DOMDocument; // init new DOMDocument $dom->loadHTML(mb_convert_encoding($html_string, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $xpath = new DOMXPath($dom); $nodes = $xpath->query('//@*'); foreach ($nodes as $node) { if($node->nodeName != "src" && $node->nodeName != "href" && $node->nodeName != "alt") { $node->parentNode->removeAttribute($node->nodeName); } } echo $dom->saveHTML(); // output cleaned HTML
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 22, Position 2 = 41
Branch analysis from position: 22
2 jumps found. (Code = 78) Position 1 = 23, Position 2 = 41
Branch analysis from position: 23
2 jumps found. (Code = 46) Position 1 = 26, Position 2 = 29
Branch analysis from position: 26
2 jumps found. (Code = 46) Position 1 = 30, Position 2 = 33
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 40
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 40
Branch analysis from position: 33
Branch analysis from position: 29
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
filename:       /in/Eomdi
function name:  (null)
number of ops:  46
compiled vars:  !0 = $html_string, !1 = $dom, !2 = $xpath, !3 = $nodes, !4 = $node
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, '%3Cp%3Eparagraph%0A++++%3Ca%3Elink%3C%2Fa%3E%0A%3C%2Fp%3E%0A%3Cdiv+class%3D%22myclass%22%3E%0A++++%3Cdiv%3Esomething%3C%2Fdiv%3E%0A++++%3Cdiv+style%3D%22mystyle%22%3Esomething%3C%2Fdiv%3E%0A++++%3Cb%3E%3Ca+href%3D%22%23%22%3Elink%3C%2Fa%3E%3C%2Fb%3E%0A++++%3Cb%3E%3Ca+href%3D%22%23%22+name%3D%22a+name%22%3Elink%3C%2Fa%3E%3C%2Fb%3E%0A++++%3Cb+style%3D%22color%3Ared%22%3Ebold%3C%2Fb%3E%0A++++%3Cimg+src%3D%22..%2Fpath%22+alt%3D%22something%22+%2F%3E%0A++++%3Cimg+src%3D%22..%2Fpath%22+alt%3D%22something%22+class%3D%22myclass%22+%2F%3E%0A%3C%2Fdiv%3E'
   21     1        NEW                                              $6      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $6
   22     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          
   23    13        NEW                                              $11     'DOMXPath'
         14        SEND_VAR_EX                                              !1
         15        DO_FCALL                                      0          
         16        ASSIGN                                                   !2, $11
   24    17        INIT_METHOD_CALL                                         !2, 'query'
         18        SEND_VAL_EX                                              '%2F%2F%40%2A'
         19        DO_FCALL                                      0  $14     
         20        ASSIGN                                                   !3, $14
   25    21      > FE_RESET_R                                       $16     !3, ->41
         22    > > FE_FETCH_R                                               $16, !4, ->41
   26    23    >   FETCH_OBJ_R                                      ~17     !4, 'nodeName'
         24        IS_NOT_EQUAL                                     ~18     ~17, 'src'
         25      > JMPZ_EX                                          ~18     ~18, ->29
         26    >   FETCH_OBJ_R                                      ~19     !4, 'nodeName'
         27        IS_NOT_EQUAL                                     ~20     ~19, 'href'
         28        BOOL                                             ~18     ~20
         29    > > JMPZ_EX                                          ~18     ~18, ->33
         30    >   FETCH_OBJ_R                                      ~21     !4, 'nodeName'
         31        IS_NOT_EQUAL                                     ~22     ~21, 'alt'
         32        BOOL                                             ~18     ~22
         33    > > JMPZ                                                     ~18, ->40
   27    34    >   FETCH_OBJ_R                                      ~23     !4, 'parentNode'
         35        INIT_METHOD_CALL                                         ~23, 'removeAttribute'
         36        CHECK_FUNC_ARG                                           
         37        FETCH_OBJ_FUNC_ARG                               $24     !4, 'nodeName'
         38        SEND_FUNC_ARG                                            $24
         39        DO_FCALL                                      0          
   25    40    > > JMP                                                      ->22
         41    >   FE_FREE                                                  $16
   31    42        INIT_METHOD_CALL                                         !1, 'saveHTML'
         43        DO_FCALL                                      0  $26     
         44        ECHO                                                     $26
         45      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.07 ms | 1003 KiB | 14 Q