3v4l.org

run code in 500+ PHP versions simultaneously
<?php $html = '<div id="one-id" class="someClassName">Some text <a href="#" title="Words" id="linkId" class="classLink">link</a> with only the class and id attrtibutes.</div>'; $dom = new DOMDocument(); $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); foreach ($dom->getElementsByTagName('*') as $node) { for ($i = $node->attributes->length - 1; $i >= 0; --$i) { $attr = $node->attributes->item($i); if (!in_array($attr->name, ['id', 'class'])) { $node->removeAttribute($attr->name); } } } echo $dom->saveHTML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 36
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 36
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 18
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 32
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 18
Branch analysis from position: 35
Branch analysis from position: 18
Branch analysis from position: 32
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
filename:       /in/5o7lb
function name:  (null)
number of ops:  41
compiled vars:  !0 = $html, !1 = $dom, !2 = $node, !3 = $i, !4 = $attr
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '%3Cdiv+id%3D%22one-id%22+class%3D%22someClassName%22%3ESome+text+%3Ca+href%3D%22%23%22+title%3D%22Words%22+id%3D%22linkId%22+class%3D%22classLink%22%3Elink%3C%2Fa%3E+with+only+the+class+and+id++attrtibutes.%3C%2Fdiv%3E'
    5     1        NEW                                                  $6      'DOMDocument'
          2        DO_FCALL                                          0          
          3        ASSIGN                                                       !1, $6
    6     4        INIT_METHOD_CALL                                             !1, 'loadHTML'
          5        SEND_VAR_EX                                                  !0
          6        SEND_VAL_EX                                                  8196
          7        DO_FCALL                                          0          
    7     8        INIT_METHOD_CALL                                             !1, 'getElementsByTagName'
          9        SEND_VAL_EX                                                  '%2A'
         10        DO_FCALL                                          0  $10     
         11      > FE_RESET_R                                           $11     $10, ->36
         12    > > FE_FETCH_R                                                   $11, !2, ->36
    8    13    >   FETCH_OBJ_R                                          ~12     !2, 'attributes'
         14        FETCH_OBJ_R                                          ~13     ~12, 'length'
         15        SUB                                                  ~14     ~13, 1
         16        ASSIGN                                                       !3, ~14
         17      > JMP                                                          ->33
    9    18    >   FETCH_OBJ_R                                          ~16     !2, 'attributes'
         19        INIT_METHOD_CALL                                             ~16, 'item'
         20        SEND_VAR_EX                                                  !3
         21        DO_FCALL                                          0  $17     
         22        ASSIGN                                                       !4, $17
   10    23        FETCH_OBJ_R                                          ~19     !4, 'name'
         24        IN_ARRAY                                             ~20     ~19, <array>
         25        BOOL_NOT                                             ~21     ~20
         26      > JMPZ                                                         ~21, ->32
   11    27    >   INIT_METHOD_CALL                                             !2, 'removeAttribute'
         28        CHECK_FUNC_ARG                                               
         29        FETCH_OBJ_FUNC_ARG                                   $22     !4, 'name'
         30        SEND_FUNC_ARG                                                $22
         31        DO_FCALL                                          0          
    8    32    >   PRE_DEC                                                      !3
         33    >   IS_SMALLER_OR_EQUAL                                          0, !3
         34      > JMPNZ                                                        ~25, ->18
    7    35    > > JMP                                                          ->12
         36    >   FE_FREE                                                      $11
   15    37        INIT_METHOD_CALL                                             !1, 'saveHTML'
         38        DO_FCALL                                          0  $26     
         39        ECHO                                                         $26
         40      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
156.94 ms | 1734 KiB | 13 Q