3v4l.org

run code in 500+ PHP versions simultaneously
<?php $html = <<<HTML <body> <img class="size-full aligncenter" src="image-name1.jpg" alt="" width="799" height="449"> <img class="size-full aligncenter" src="image-name2.jpg" alt="" width="799" height="449"> <img class="size-full aligncenter" src="image-name3.jpg" alt="" width="799" height="449"> </body> HTML; $dom = new DOMDocument; $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $xpath = new DOMXPath($dom); foreach ($xpath->query('//img[@alt=""]') as $img) { $img->setAttribute( 'alt', pathinfo( $img->getAttribute('src'), PATHINFO_FILENAME ) ); } echo $dom->saveHTML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 29
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 29
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
filename:       /in/IIBG1
function name:  (null)
number of ops:  34
compiled vars:  !0 = $html, !1 = $dom, !2 = $xpath, !3 = $img
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '%3Cbody%3E%0A%3Cimg+class%3D%22size-full+aligncenter%22+src%3D%22image-name1.jpg%22+alt%3D%22%22+width%3D%22799%22+height%3D%22449%22%3E%0A%0A%3Cimg+class%3D%22size-full+aligncenter%22+src%3D%22image-name2.jpg%22+alt%3D%22%22+width%3D%22799%22+height%3D%22449%22%3E%0A%0A%3Cimg+class%3D%22size-full+aligncenter%22+src%3D%22image-name3.jpg%22+alt%3D%22%22+width%3D%22799%22+height%3D%22449%22%3E%0A%3C%2Fbody%3E'
   13     1        NEW                                                  $5      'DOMDocument'
          2        DO_FCALL                                          0          
          3        ASSIGN                                                       !1, $5
   14     4        INIT_METHOD_CALL                                             !1, 'loadHTML'
          5        SEND_VAR_EX                                                  !0
          6        SEND_VAL_EX                                                  8196
          7        DO_FCALL                                          0          
   15     8        NEW                                                  $9      'DOMXPath'
          9        SEND_VAR_EX                                                  !1
         10        DO_FCALL                                          0          
         11        ASSIGN                                                       !2, $9
   16    12        INIT_METHOD_CALL                                             !2, 'query'
         13        SEND_VAL_EX                                                  '%2F%2Fimg%5B%40alt%3D%22%22%5D'
         14        DO_FCALL                                          0  $12     
         15      > FE_RESET_R                                           $13     $12, ->29
         16    > > FE_FETCH_R                                                   $13, !3, ->29
   17    17    >   INIT_METHOD_CALL                                             !3, 'setAttribute'
   18    18        SEND_VAL_EX                                                  'alt'
   19    19        INIT_FCALL                                                   'pathinfo'
   20    20        INIT_METHOD_CALL                                             !3, 'getAttribute'
         21        SEND_VAL_EX                                                  'src'
         22        DO_FCALL                                          0  $14     
         23        SEND_VAR                                                     $14
   21    24        SEND_VAL                                                     8
   19    25        DO_ICALL                                             $15     
   21    26        SEND_VAR_NO_REF_EX                                           $15
   17    27        DO_FCALL                                          0          
   16    28      > JMP                                                          ->16
         29    >   FE_FREE                                                      $13
   25    30        INIT_METHOD_CALL                                             !1, 'saveHTML'
         31        DO_FCALL                                          0  $17     
         32        ECHO                                                         $17
         33      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
151.46 ms | 1943 KiB | 14 Q