3v4l.org

run code in 500+ PHP versions simultaneously
<?php $html = <<<HTML <div> <img src="/relative/url/img.jpg" /> <form action="/"></form> <form action="/contact-us/"></form> <a href='/relative/url/'>Note the Single Quote</a> <img src="//example.com/protocol-relative-img.jpg" /> </div> HTML; $domain = '//example.com'; $targets = [ "//img[not(starts-with(@src, '//'))]", "//form[not(starts-with(@action, '//'))]", "//a[not(starts-with(@href, '//'))]" ]; $dom = new DOMDocument; $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $xpath = new DOMXPath($dom); foreach ($xpath->query(implode('|', $targets)) as $node) { if ($src = $node->getAttribute('src')) { $node->setAttribute('src', $domain . $src); } elseif ($action = $node->getAttribute('action')) { $node->setAttribute('action', $domain . $action); } else { $node->setAttribute('href', $domain . $node->getAttribute('href')); } } echo $dom->saveHTML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 19, Position 2 = 51
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 51
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 31
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 42
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 51
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
filename:       /in/Ut8Dr
function name:  (null)
number of ops:  56
compiled vars:  !0 = $html, !1 = $domain, !2 = $targets, !3 = $dom, !4 = $xpath, !5 = $node, !6 = $src, !7 = $action
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '%3Cdiv%3E%0A%3Cimg+src%3D%22%2Frelative%2Furl%2Fimg.jpg%22+%2F%3E%0A%3Cform+action%3D%22%2F%22%3E%3C%2Fform%3E%0A%3Cform+action%3D%22%2Fcontact-us%2F%22%3E%3C%2Fform%3E%0A%3Ca+href%3D%27%2Frelative%2Furl%2F%27%3ENote+the+Single+Quote%3C%2Fa%3E%0A%3Cimg+src%3D%22%2F%2Fexample.com%2Fprotocol-relative-img.jpg%22+%2F%3E%0A%3C%2Fdiv%3E'
   13     1        ASSIGN                                                       !1, '%2F%2Fexample.com'
   14     2        ASSIGN                                                       !2, <array>
   20     3        NEW                                                  $11     'DOMDocument'
          4        DO_FCALL                                          0          
          5        ASSIGN                                                       !3, $11
   21     6        INIT_METHOD_CALL                                             !3, 'loadHTML'
          7        SEND_VAR_EX                                                  !0
          8        SEND_VAL_EX                                                  8196
          9        DO_FCALL                                          0          
   22    10        NEW                                                  $15     'DOMXPath'
         11        SEND_VAR_EX                                                  !3
         12        DO_FCALL                                          0          
         13        ASSIGN                                                       !4, $15
   23    14        INIT_METHOD_CALL                                             !4, 'query'
         15        FRAMELESS_ICALL_2                implode             ~18     '%7C', !2
         16        SEND_VAL_EX                                                  ~18
         17        DO_FCALL                                          0  $19     
         18      > FE_RESET_R                                           $20     $19, ->51
         19    > > FE_FETCH_R                                                   $20, !5, ->51
   24    20    >   INIT_METHOD_CALL                                             !5, 'getAttribute'
         21        SEND_VAL_EX                                                  'src'
         22        DO_FCALL                                          0  $21     
         23        ASSIGN                                               ~22     !6, $21
         24      > JMPZ                                                         ~22, ->31
   25    25    >   INIT_METHOD_CALL                                             !5, 'setAttribute'
         26        SEND_VAL_EX                                                  'src'
         27        CONCAT                                               ~23     !1, !6
         28        SEND_VAL_EX                                                  ~23
         29        DO_FCALL                                          0          
   24    30      > JMP                                                          ->50
   26    31    >   INIT_METHOD_CALL                                             !5, 'getAttribute'
         32        SEND_VAL_EX                                                  'action'
         33        DO_FCALL                                          0  $25     
         34        ASSIGN                                               ~26     !7, $25
         35      > JMPZ                                                         ~26, ->42
   27    36    >   INIT_METHOD_CALL                                             !5, 'setAttribute'
         37        SEND_VAL_EX                                                  'action'
         38        CONCAT                                               ~27     !1, !7
         39        SEND_VAL_EX                                                  ~27
         40        DO_FCALL                                          0          
   26    41      > JMP                                                          ->50
   29    42    >   INIT_METHOD_CALL                                             !5, 'setAttribute'
         43        SEND_VAL_EX                                                  'href'
         44        INIT_METHOD_CALL                                             !5, 'getAttribute'
         45        SEND_VAL_EX                                                  'href'
         46        DO_FCALL                                          0  $29     
         47        CONCAT                                               ~30     !1, $29
         48        SEND_VAL_EX                                                  ~30
         49        DO_FCALL                                          0          
   23    50    > > JMP                                                          ->19
         51    >   FE_FREE                                                      $20
   32    52        INIT_METHOD_CALL                                             !3, 'saveHTML'
         53        DO_FCALL                                          0  $32     
         54        ECHO                                                         $32
         55      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
172.66 ms | 3395 KiB | 13 Q