3v4l.org

run code in 300+ 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 = 22, Position 2 = 54
Branch analysis from position: 22
2 jumps found. (Code = 78) Position 1 = 23, Position 2 = 54
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 34
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 45
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 54
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 54
filename:       /in/Ut8Dr
function name:  (null)
number of ops:  59
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        INIT_FCALL                                               'implode'
         16        SEND_VAL                                                 '%7C'
         17        SEND_VAR                                                 !2
         18        DO_ICALL                                         $18     
         19        SEND_VAR_NO_REF_EX                                       $18
         20        DO_FCALL                                      0  $19     
         21      > FE_RESET_R                                       $20     $19, ->54
         22    > > FE_FETCH_R                                               $20, !5, ->54
   24    23    >   INIT_METHOD_CALL                                         !5, 'getAttribute'
         24        SEND_VAL_EX                                              'src'
         25        DO_FCALL                                      0  $21     
         26        ASSIGN                                           ~22     !6, $21
         27      > JMPZ                                                     ~22, ->34
   25    28    >   INIT_METHOD_CALL                                         !5, 'setAttribute'
         29        SEND_VAL_EX                                              'src'
         30        CONCAT                                           ~23     !1, !6
         31        SEND_VAL_EX                                              ~23
         32        DO_FCALL                                      0          
   24    33      > JMP                                                      ->53
   26    34    >   INIT_METHOD_CALL                                         !5, 'getAttribute'
         35        SEND_VAL_EX                                              'action'
         36        DO_FCALL                                      0  $25     
         37        ASSIGN                                           ~26     !7, $25
         38      > JMPZ                                                     ~26, ->45
   27    39    >   INIT_METHOD_CALL                                         !5, 'setAttribute'
         40        SEND_VAL_EX                                              'action'
         41        CONCAT                                           ~27     !1, !7
         42        SEND_VAL_EX                                              ~27
         43        DO_FCALL                                      0          
   26    44      > JMP                                                      ->53
   29    45    >   INIT_METHOD_CALL                                         !5, 'setAttribute'
         46        SEND_VAL_EX                                              'href'
         47        INIT_METHOD_CALL                                         !5, 'getAttribute'
         48        SEND_VAL_EX                                              'href'
         49        DO_FCALL                                      0  $29     
         50        CONCAT                                           ~30     !1, $29
         51        SEND_VAL_EX                                              ~30
         52        DO_FCALL                                      0          
   23    53    > > JMP                                                      ->22
         54    >   FE_FREE                                                  $20
   32    55        INIT_METHOD_CALL                                         !3, 'saveHTML'
         56        DO_FCALL                                      0  $32     
         57        ECHO                                                     $32
         58      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.44 ms | 1015 KiB | 14 Q