3v4l.org

run code in 300+ PHP versions simultaneously
<?php $homepage = "https://example.com/"; $html = '<img class="drt" src="100.png"><img src="../101.png"><img src="/102.png"><img src="103.png">'; $dom = new DOMDocument(); $dom->loadHTML($html); foreach ($dom->getElementsByTagName('img') as $img) { $src = $img->getAttribute('src'); $src = $homepage.basename($src); $img->setAttribute('src', $src); } // hacky way! remove unwanted doctype ect $ret = preg_replace('~<(?:!DOCTYPE|/?(?:html|body|head))[^>]*>\s*~i', '', $dom->saveHTML()); echo trim(str_replace('<meta http-equiv="Content-Type" content="text/html;charset=utf-8">', '', $ret)); // proper way! but you dont have correct DOM, no <body> // remove <!DOCTYPE //$dom->removeChild($dom->doctype); // remove <html><body></body></html> //$dom->replaceChild($dom->firstChild->firstChild->firstChild, $dom->firstChild); // //echo $dom->saveHTML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 27
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 27
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/1sf3B
function name:  (null)
number of ops:  46
compiled vars:  !0 = $homepage, !1 = $html, !2 = $dom, !3 = $img, !4 = $src, !5 = $ret
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'https%3A%2F%2Fexample.com%2F'
    3     1        ASSIGN                                                   !1, '%3Cimg+class%3D%22drt%22+src%3D%22100.png%22%3E%3Cimg+src%3D%22..%2F101.png%22%3E%3Cimg+src%3D%22%2F102.png%22%3E%3Cimg+src%3D%22103.png%22%3E'
    5     2        NEW                                              $8      'DOMDocument'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !2, $8
    6     5        INIT_METHOD_CALL                                         !2, 'loadHTML'
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0          
    8     8        INIT_METHOD_CALL                                         !2, 'getElementsByTagName'
          9        SEND_VAL_EX                                              'img'
         10        DO_FCALL                                      0  $12     
         11      > FE_RESET_R                                       $13     $12, ->27
         12    > > FE_FETCH_R                                               $13, !3, ->27
    9    13    >   INIT_METHOD_CALL                                         !3, 'getAttribute'
         14        SEND_VAL_EX                                              'src'
         15        DO_FCALL                                      0  $14     
         16        ASSIGN                                                   !4, $14
   10    17        INIT_FCALL                                               'basename'
         18        SEND_VAR                                                 !4
         19        DO_ICALL                                         $16     
         20        CONCAT                                           ~17     !0, $16
         21        ASSIGN                                                   !4, ~17
   11    22        INIT_METHOD_CALL                                         !3, 'setAttribute'
         23        SEND_VAL_EX                                              'src'
         24        SEND_VAR_EX                                              !4
         25        DO_FCALL                                      0          
    8    26      > JMP                                                      ->12
         27    >   FE_FREE                                                  $13
   15    28        INIT_FCALL                                               'preg_replace'
         29        SEND_VAL                                                 '%7E%3C%28%3F%3A%21DOCTYPE%7C%2F%3F%28%3F%3Ahtml%7Cbody%7Chead%29%29%5B%5E%3E%5D%2A%3E%5Cs%2A%7Ei'
         30        SEND_VAL                                                 ''
         31        INIT_METHOD_CALL                                         !2, 'saveHTML'
         32        DO_FCALL                                      0  $20     
         33        SEND_VAR                                                 $20
         34        DO_ICALL                                         $21     
         35        ASSIGN                                                   !5, $21
   16    36        INIT_FCALL                                               'trim'
         37        INIT_FCALL                                               'str_replace'
         38        SEND_VAL                                                 '%3Cmeta+http-equiv%3D%22Content-Type%22+content%3D%22text%2Fhtml%3Bcharset%3Dutf-8%22%3E'
         39        SEND_VAL                                                 ''
         40        SEND_VAR                                                 !5
         41        DO_ICALL                                         $23     
         42        SEND_VAR                                                 $23
         43        DO_ICALL                                         $24     
         44        ECHO                                                     $24
   24    45      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.77 ms | 1089 KiB | 17 Q