3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <div> Here is an img tag with no qs <img src="http://www.example.com/a.jpg">, an img with no src <img title="to be determined">, and here is another with a qs <img src="http://www.example.com/b.jpg?height=900">. Here is a <iframe src="http://www.example.com/c.jpg?foo=bar"></iframe> and a submit button <input type="image" src="http://www.example.com/d.jpg?boo=far&what=now" alt="Submit"> </div> HTML; $newUrl = 'https://www.example.com/new.jpg'; $dom = new DOMDocument(); libxml_use_internal_errors(true); $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $xpath = new DOMXPath($dom); foreach ($xpath->query("//img/@src") as $src) { $src->value = $newUrl; } echo $dom->saveHTML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 24
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 24
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/o4XM0
function name:  (null)
number of ops:  29
compiled vars:  !0 = $html, !1 = $newUrl, !2 = $dom, !3 = $xpath, !4 = $src
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Cdiv%3E%0AHere+is+an+img+tag+with+no+qs+%3Cimg+src%3D%22http%3A%2F%2Fwww.example.com%2Fa.jpg%22%3E%2C%0A+an+img+with+no+src+%3Cimg+title%3D%22to+be+determined%22%3E%2C%0A+and+here+is+another+with+a+qs+%3Cimg+src%3D%22http%3A%2F%2Fwww.example.com%2Fb.jpg%3Fheight%3D900%22%3E.%0AHere+is+a+%3Ciframe+src%3D%22http%3A%2F%2Fwww.example.com%2Fc.jpg%3Ffoo%3Dbar%22%3E%3C%2Fiframe%3E+and%0A+a+submit+button+%3Cinput+type%3D%22image%22+src%3D%22http%3A%2F%2Fwww.example.com%2Fd.jpg%3Fboo%3Dfar%26what%3Dnow%22+alt%3D%22Submit%22%3E%0A%3C%2Fdiv%3E'
   13     1        ASSIGN                                                   !1, 'https%3A%2F%2Fwww.example.com%2Fnew.jpg'
   15     2        NEW                                              $7      'DOMDocument'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !2, $7
   16     5        INIT_FCALL                                               'libxml_use_internal_errors'
          6        SEND_VAL                                                 <true>
          7        DO_ICALL                                                 
   17     8        INIT_METHOD_CALL                                         !2, 'loadHTML'
          9        SEND_VAR_EX                                              !0
         10        SEND_VAL_EX                                              8196
         11        DO_FCALL                                      0          
   18    12        NEW                                              $12     'DOMXPath'
         13        SEND_VAR_EX                                              !2
         14        DO_FCALL                                      0          
         15        ASSIGN                                                   !3, $12
   19    16        INIT_METHOD_CALL                                         !3, 'query'
         17        SEND_VAL_EX                                              '%2F%2Fimg%2F%40src'
         18        DO_FCALL                                      0  $15     
         19      > FE_RESET_R                                       $16     $15, ->24
         20    > > FE_FETCH_R                                               $16, !4, ->24
   20    21    >   ASSIGN_OBJ                                               !4, 'value'
         22        OP_DATA                                                  !1
   19    23      > JMP                                                      ->20
         24    >   FE_FREE                                                  $16
   23    25        INIT_METHOD_CALL                                         !2, 'saveHTML'
         26        DO_FCALL                                      0  $18     
         27        ECHO                                                     $18
         28      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.36 ms | 1011 KiB | 14 Q