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'; $tagsAndAttributes = [ 'img' => 'src', 'form' => 'action', 'a' => 'href' ]; $dom = new DOMDocument; $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $xpath = new DOMXPath($dom); foreach ($tagsAndAttributes as $tag => $attr) { foreach ($xpath->query("//{$tag}[not(starts-with(@{$attr}, '//'))]") as $node) { $node->setAttribute($attr, $domain . $node->getAttribute($attr)); } } echo $dom->saveHTML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 38
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 38
Branch analysis from position: 16
2 jumps found. (Code = 77) Position 1 = 26, Position 2 = 36
Branch analysis from position: 26
2 jumps found. (Code = 78) Position 1 = 27, Position 2 = 36
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 36
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
filename:       /in/1taUc
function name:  (null)
number of ops:  43
compiled vars:  !0 = $html, !1 = $domain, !2 = $tagsAndAttributes, !3 = $dom, !4 = $xpath, !5 = $attr, !6 = $tag, !7 = $node
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      > FE_RESET_R                                           $18     !2, ->38
         15    > > FE_FETCH_R                                           ~19     $18, !5, ->38
         16    >   ASSIGN                                                       !6, ~19
   24    17        INIT_METHOD_CALL                                             !4, 'query'
         18        ROPE_INIT                                         5  ~22     '%2F%2F'
         19        ROPE_ADD                                          1  ~22     ~22, !6
         20        ROPE_ADD                                          2  ~22     ~22, '%5Bnot%28starts-with%28%40'
         21        ROPE_ADD                                          3  ~22     ~22, !5
         22        ROPE_END                                          4  ~21     ~22, '%2C+%27%2F%2F%27%29%29%5D'
         23        SEND_VAL_EX                                                  ~21
         24        DO_FCALL                                          0  $25     
         25      > FE_RESET_R                                           $26     $25, ->36
         26    > > FE_FETCH_R                                                   $26, !7, ->36
   25    27    >   INIT_METHOD_CALL                                             !7, 'setAttribute'
         28        SEND_VAR_EX                                                  !5
         29        INIT_METHOD_CALL                                             !7, 'getAttribute'
         30        SEND_VAR_EX                                                  !5
         31        DO_FCALL                                          0  $27     
         32        CONCAT                                               ~28     !1, $27
         33        SEND_VAL_EX                                                  ~28
         34        DO_FCALL                                          0          
   24    35      > JMP                                                          ->26
         36    >   FE_FREE                                                      $26
   23    37      > JMP                                                          ->15
         38    >   FE_FREE                                                      $18
   28    39        INIT_METHOD_CALL                                             !3, 'saveHTML'
         40        DO_FCALL                                          0  $30     
         41        ECHO                                                         $30
         42      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
166.53 ms | 2267 KiB | 13 Q