3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <p id="paragraph" class="green"> This is a paragraph with an image <img src="/path/to/image.jpg" width="50" height="75"/> </p> HTML; $dom = new DOMDocument; $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $xpath = new DOMXPath($dom); foreach ($xpath->query('//@*[not(name()="src")]') as $attr) { $attr->parentNode->removeAttribute($attr->nodeName); } echo $dom->saveHTML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 24
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 24
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/R8pAi
function name:  (null)
number of ops:  29
compiled vars:  !0 = $html, !1 = $dom, !2 = $xpath, !3 = $attr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Cp+id%3D%22paragraph%22+class%3D%22green%22%3E%0A++++This+is+a+paragraph+with+an+image+%3Cimg+src%3D%22%2Fpath%2Fto%2Fimage.jpg%22+width%3D%2250%22+height%3D%2275%22%2F%3E%0A%3C%2Fp%3E'
    9     1        NEW                                              $5      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $5
   10     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        SEND_VAL_EX                                              8196
          7        DO_FCALL                                      0          
   11     8        NEW                                              $9      'DOMXPath'
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !2, $9
   12    12        INIT_METHOD_CALL                                         !2, 'query'
         13        SEND_VAL_EX                                              '%2F%2F%40%2A%5Bnot%28name%28%29%3D%22src%22%29%5D'
         14        DO_FCALL                                      0  $12     
         15      > FE_RESET_R                                       $13     $12, ->24
         16    > > FE_FETCH_R                                               $13, !3, ->24
   13    17    >   FETCH_OBJ_R                                      ~14     !3, 'parentNode'
         18        INIT_METHOD_CALL                                         ~14, 'removeAttribute'
         19        CHECK_FUNC_ARG                                           
         20        FETCH_OBJ_FUNC_ARG                               $15     !3, 'nodeName'
         21        SEND_FUNC_ARG                                            $15
         22        DO_FCALL                                      0          
   12    23      > JMP                                                      ->16
         24    >   FE_FREE                                                  $13
   15    25        INIT_METHOD_CALL                                         !1, 'saveHTML'
         26        DO_FCALL                                      0  $17     
         27        ECHO                                                     $17
         28      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.03 ms | 1000 KiB | 13 Q