3v4l.org

run code in 500+ PHP versions simultaneously
<?php $content = '<figure class="image image-style-align-left"><img src="https://placekitten.com/g/200/300"></figure><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>'; $dom = new DOMDocument(); libxml_use_internal_errors(true); // this needs to be encoded otherwise special characters get messed up. $domPart = mb_convert_encoding($content, 'HTML-ENTITIES', "UTF-8"); $dom->loadHTML($domPart, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $domFigures = $dom->getElementsByTagName('figure'); foreach ($domFigures as $domFigure) { $img = $domFigure->getElementsByTagName('img')[0]; if ($img) { $img->setAttribute('src', "https://placekitten.com/g/400/500"); } } $result = $dom->saveHTML(); print_r($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 22, Position 2 = 34
Branch analysis from position: 22
2 jumps found. (Code = 78) Position 1 = 23, Position 2 = 34
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 33
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 33
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/AgIjB
function name:  (null)
number of ops:  42
compiled vars:  !0 = $content, !1 = $dom, !2 = $domPart, !3 = $domFigures, !4 = $domFigure, !5 = $img, !6 = $result
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '%3Cfigure+class%3D%22image+image-style-align-left%22%3E%3Cimg+src%3D%22https%3A%2F%2Fplacekitten.com%2Fg%2F200%2F300%22%3E%3C%2Ffigure%3E%3Cp%3ELorem+ipsum+dolor+sit+amet%2C+consectetuer+adipiscing+elit.%3C%2Fp%3E'
    5     1        NEW                                                  $8      'DOMDocument'
          2        DO_FCALL                                          0          
          3        ASSIGN                                                       !1, $8
    6     4        INIT_FCALL                                                   'libxml_use_internal_errors'
          5        SEND_VAL                                                     <true>
          6        DO_ICALL                                                     
    9     7        INIT_FCALL                                                   'mb_convert_encoding'
          8        SEND_VAR                                                     !0
          9        SEND_VAL                                                     'HTML-ENTITIES'
         10        SEND_VAL                                                     'UTF-8'
         11        DO_ICALL                                             $12     
         12        ASSIGN                                                       !2, $12
   10    13        INIT_METHOD_CALL                                             !1, 'loadHTML'
         14        SEND_VAR_EX                                                  !2
         15        SEND_VAL_EX                                                  8196
         16        DO_FCALL                                          0          
   12    17        INIT_METHOD_CALL                                             !1, 'getElementsByTagName'
         18        SEND_VAL_EX                                                  'figure'
         19        DO_FCALL                                          0  $15     
         20        ASSIGN                                                       !3, $15
   14    21      > FE_RESET_R                                           $17     !3, ->34
         22    > > FE_FETCH_R                                                   $17, !4, ->34
   16    23    >   INIT_METHOD_CALL                                             !4, 'getElementsByTagName'
         24        SEND_VAL_EX                                                  'img'
         25        DO_FCALL                                          0  $18     
         26        FETCH_DIM_R                                          ~19     $18, 0
         27        ASSIGN                                                       !5, ~19
   18    28      > JMPZ                                                         !5, ->33
   19    29    >   INIT_METHOD_CALL                                             !5, 'setAttribute'
         30        SEND_VAL_EX                                                  'src'
         31        SEND_VAL_EX                                                  'https%3A%2F%2Fplacekitten.com%2Fg%2F400%2F500'
         32        DO_FCALL                                          0          
   14    33    > > JMP                                                          ->22
         34    >   FE_FREE                                                      $17
   24    35        INIT_METHOD_CALL                                             !1, 'saveHTML'
         36        DO_FCALL                                          0  $22     
         37        ASSIGN                                                       !6, $22
   26    38        INIT_FCALL                                                   'print_r'
         39        SEND_VAR                                                     !6
         40        DO_ICALL                                                     
         41      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
166.17 ms | 2165 KiB | 16 Q