3v4l.org

run code in 500+ PHP versions simultaneously
<?php $content = <<<DATA <body> <img src="not-this-one.jpg" alt="unique"/> <div id="1"> <img src="this-one.jpg" alt="som title"/> <img src="this-one-no-alt.jpg"/> </div> </body> DATA; $dom = new DOMDocument('1.0', 'UTF-8'); $dom->loadHTML($content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $images = $xpath->query('//div/img'); $focuskw = "NEWVALUE"; foreach ($dom->getElementsByTagName('div') as $div) { foreach ($div->getElementsByTagName('img') as $img) { $img->setAttribute('alt', 'http://google.com/'); } } $content = $dom->saveHTML(); print_r($content);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 19, Position 2 = 32
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 32
Branch analysis from position: 20
2 jumps found. (Code = 77) Position 1 = 24, Position 2 = 30
Branch analysis from position: 24
2 jumps found. (Code = 78) Position 1 = 25, Position 2 = 30
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 30
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
filename:       /in/Yjm0s
function name:  (null)
number of ops:  40
compiled vars:  !0 = $content, !1 = $dom, !2 = $images, !3 = $xpath, !4 = $focuskw, !5 = $div, !6 = $img
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '%3Cbody%3E%0A%3Cimg+src%3D%22not-this-one.jpg%22+alt%3D%22unique%22%2F%3E%0A%3Cdiv+id%3D%221%22%3E%0A++%3Cimg+src%3D%22this-one.jpg%22+alt%3D%22som+title%22%2F%3E%0A++%3Cimg+src%3D%22this-one-no-alt.jpg%22%2F%3E%0A%3C%2Fdiv%3E%0A%3C%2Fbody%3E'
   13     1        NEW                                                  $8      'DOMDocument'
          2        SEND_VAL_EX                                                  '1.0'
          3        SEND_VAL_EX                                                  'UTF-8'
          4        DO_FCALL                                          0          
          5        ASSIGN                                                       !1, $8
   14     6        INIT_METHOD_CALL                                             !1, 'loadHTML'
          7        SEND_VAR_EX                                                  !0
          8        SEND_VAL_EX                                                  8196
          9        DO_FCALL                                          0          
   16    10        INIT_METHOD_CALL                                             !3, 'query'
         11        SEND_VAL_EX                                                  '%2F%2Fdiv%2Fimg'
         12        DO_FCALL                                          0  $12     
         13        ASSIGN                                                       !2, $12
   17    14        ASSIGN                                                       !4, 'NEWVALUE'
   18    15        INIT_METHOD_CALL                                             !1, 'getElementsByTagName'
         16        SEND_VAL_EX                                                  'div'
         17        DO_FCALL                                          0  $15     
         18      > FE_RESET_R                                           $16     $15, ->32
         19    > > FE_FETCH_R                                                   $16, !5, ->32
   19    20    >   INIT_METHOD_CALL                                             !5, 'getElementsByTagName'
         21        SEND_VAL_EX                                                  'img'
         22        DO_FCALL                                          0  $17     
         23      > FE_RESET_R                                           $18     $17, ->30
         24    > > FE_FETCH_R                                                   $18, !6, ->30
   20    25    >   INIT_METHOD_CALL                                             !6, 'setAttribute'
         26        SEND_VAL_EX                                                  'alt'
         27        SEND_VAL_EX                                                  'http%3A%2F%2Fgoogle.com%2F'
         28        DO_FCALL                                          0          
   19    29      > JMP                                                          ->24
         30    >   FE_FREE                                                      $18
   18    31      > JMP                                                          ->19
         32    >   FE_FREE                                                      $16
   23    33        INIT_METHOD_CALL                                             !1, 'saveHTML'
         34        DO_FCALL                                          0  $20     
         35        ASSIGN                                                       !0, $20
   24    36        INIT_FCALL                                                   'print_r'
         37        SEND_VAR                                                     !0
         38        DO_ICALL                                                     
         39      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
163.24 ms | 2181 KiB | 14 Q