3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <div> <img src="image/abc.png" alt="test" width="50" height="50"> <img src="http://example.com/image/abc.png" alt="test" width="50" height="50"> <img src="/image/abc.png" alt="test" width="50" height="50"> <iframe src="image/abc.png" alt="test" width="50" height="50"></iframe> </div> HTML; $base = "http://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, '$base'))]") 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 = 20, Position 2 = 34
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 34
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/subbr
function name:  (null)
number of ops:  39
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%22image%2Fabc.png%22+alt%3D%22test%22+width%3D%2250%22+height%3D%2250%22%3E%0A+++%3Cimg+src%3D%22http%3A%2F%2Fexample.com%2Fimage%2Fabc.png%22+alt%3D%22test%22+width%3D%2250%22+height%3D%2250%22%3E%0A+++%3Cimg+src%3D%22%2Fimage%2Fabc.png%22+alt%3D%22test%22+width%3D%2250%22+height%3D%2250%22%3E%0A+++%3Ciframe+src%3D%22image%2Fabc.png%22+alt%3D%22test%22+width%3D%2250%22+height%3D%2250%22%3E%3C%2Fiframe%3E%0A%3C%2Fdiv%3E'
   12     1        ASSIGN                                                   !1, 'http%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        ROPE_INIT                                     3  ~15     '%2F%2Fimg%5Bnot%28starts-with%28%40src%2C+%27'
         15        ROPE_ADD                                      1  ~15     ~15, !1
         16        ROPE_END                                      2  ~14     ~15, '%27%29%29%5D'
         17        SEND_VAL_EX                                              ~14
         18        DO_FCALL                                      0  $17     
         19      > FE_RESET_R                                       $18     $17, ->34
         20    > > FE_FETCH_R                                               $18, !4, ->34
   18    21    >   INIT_METHOD_CALL                                         !4, 'setAttribute'
         22        SEND_VAL_EX                                              'src'
         23        INIT_FCALL                                               'ltrim'
         24        INIT_METHOD_CALL                                         !4, 'getAttribute'
         25        SEND_VAL_EX                                              'src'
         26        DO_FCALL                                      0  $19     
         27        SEND_VAR                                                 $19
         28        SEND_VAL                                                 '%2F'
         29        DO_ICALL                                         $20     
         30        CONCAT                                           ~21     !1, $20
         31        SEND_VAL_EX                                              ~21
         32        DO_FCALL                                      0          
   17    33      > JMP                                                      ->20
         34    >   FE_FREE                                                  $18
   20    35        INIT_METHOD_CALL                                         !2, 'saveHTML'
         36        DO_FCALL                                      0  $23     
         37        ECHO                                                     $23
         38      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
241.76 ms | 1015 KiB | 14 Q