3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <div class="image"> <img src="https://www.gravatar.com/avatar/" alt="test" width="50" height="50"> </div> HTML; $dom = new DOMDocument; $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $xpath = new DOMXPath($dom); // using a loop in case there are multiple occurrences foreach ($xpath->query("//div[contains(@class, 'image')]/img") as $node) { $node->setAttribute('data-mfp-src', $node->getAttribute('src')); } echo $dom->saveHTML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 25
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 25
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/KqqXK
function name:  (null)
number of ops:  30
compiled vars:  !0 = $html, !1 = $dom, !2 = $xpath, !3 = $node
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%3Cdiv+class%3D%22image%22%3E%0A+++%3Cimg+src%3D%22https%3A%2F%2Fwww.gravatar.com%2Favatar%2F%22+alt%3D%22test%22+width%3D%2250%22+height%3D%2250%22%3E%0A%3C%2Fdiv%3E'
    8     1        NEW                                              $5      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $5
    9     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        SEND_VAL_EX                                              8196
          7        DO_FCALL                                      0          
   10     8        NEW                                              $9      'DOMXPath'
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !2, $9
   12    12        INIT_METHOD_CALL                                         !2, 'query'
         13        SEND_VAL_EX                                              '%2F%2Fdiv%5Bcontains%28%40class%2C+%27image%27%29%5D%2Fimg'
         14        DO_FCALL                                      0  $12     
         15      > FE_RESET_R                                       $13     $12, ->25
         16    > > FE_FETCH_R                                               $13, !3, ->25
   13    17    >   INIT_METHOD_CALL                                         !3, 'setAttribute'
         18        SEND_VAL_EX                                              'data-mfp-src'
         19        INIT_METHOD_CALL                                         !3, 'getAttribute'
         20        SEND_VAL_EX                                              'src'
         21        DO_FCALL                                      0  $14     
         22        SEND_VAR_NO_REF_EX                                       $14
         23        DO_FCALL                                      0          
   12    24      > JMP                                                      ->16
         25    >   FE_FREE                                                  $13
   15    26        INIT_METHOD_CALL                                         !1, 'saveHTML'
         27        DO_FCALL                                      0  $16     
         28        ECHO                                                     $16
         29      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
126.53 ms | 1449 KiB | 13 Q