3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <div> <img src="docs/relative/url/img.jpg" /> <img src="/docs/relative/url/img.jpg" /> <img src="https://docs/relative/url/img.jpg" /> <img src="http://docs/relative/url/img.jpg" /> </div> HTML; $base = 'https://example.com/'; $dom = new DOMDocument; $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $xpath = new DOMXPath($dom); foreach ($xpath->query("//img[not(starts-with(@src, 'http'))]") as $node) { $node->setAttribute('src', $base . ltrim($node->getAttribute('src'), '/')); } echo $dom->saveHTML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 31
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 31
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/PuGgH
function name:  (null)
number of ops:  36
compiled vars:  !0 = $html, !1 = $base, !2 = $dom, !3 = $xpath, !4 = $node
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Cdiv%3E%0A%3Cimg+src%3D%22docs%2Frelative%2Furl%2Fimg.jpg%22+%2F%3E%0A%3Cimg+src%3D%22%2Fdocs%2Frelative%2Furl%2Fimg.jpg%22+%2F%3E%0A%3Cimg+src%3D%22https%3A%2F%2Fdocs%2Frelative%2Furl%2Fimg.jpg%22+%2F%3E%0A%3Cimg+src%3D%22http%3A%2F%2Fdocs%2Frelative%2Furl%2Fimg.jpg%22+%2F%3E%0A%3C%2Fdiv%3E'
   12     1        ASSIGN                                                   !1, 'https%3A%2F%2Fexample.com%2F'
   14     2        NEW                                              $7      'DOMDocument'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !2, $7
   15     5        INIT_METHOD_CALL                                         !2, 'loadHTML'
          6        SEND_VAR_EX                                              !0
          7        SEND_VAL_EX                                              8196
          8        DO_FCALL                                      0          
   16     9        NEW                                              $11     'DOMXPath'
         10        SEND_VAR_EX                                              !2
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !3, $11
   17    13        INIT_METHOD_CALL                                         !3, 'query'
         14        SEND_VAL_EX                                              '%2F%2Fimg%5Bnot%28starts-with%28%40src%2C+%27http%27%29%29%5D'
         15        DO_FCALL                                      0  $14     
         16      > FE_RESET_R                                       $15     $14, ->31
         17    > > FE_FETCH_R                                               $15, !4, ->31
   18    18    >   INIT_METHOD_CALL                                         !4, 'setAttribute'
         19        SEND_VAL_EX                                              'src'
         20        INIT_FCALL                                               'ltrim'
         21        INIT_METHOD_CALL                                         !4, 'getAttribute'
         22        SEND_VAL_EX                                              'src'
         23        DO_FCALL                                      0  $16     
         24        SEND_VAR                                                 $16
         25        SEND_VAL                                                 '%2F'
         26        DO_ICALL                                         $17     
         27        CONCAT                                           ~18     !1, $17
         28        SEND_VAL_EX                                              ~18
         29        DO_FCALL                                      0          
   17    30      > JMP                                                      ->17
         31    >   FE_FREE                                                  $15
   20    32        INIT_METHOD_CALL                                         !2, 'saveHTML'
         33        DO_FCALL                                      0  $20     
         34        ECHO                                                     $20
         35      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.79 ms | 1002 KiB | 14 Q