3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<< STR <div class="container"> <h1>The Page Title</h1> <img src="MyImage.JPG" class="graphic" /> <p>Some body copy...</p> <img class="graphic" src="misc/SecondImage.JPG" /> </div> STR; $dom = new DOMDocument; $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); // Get all images $images = $dom->getElementsByTagName('img'); foreach ($images as $img) { $newSrc = preg_replace_callback('~[^/]+$~', function($match) { // Change file names to lowercase return strtolower($match[0]); }, $img->getAttribute('src')); // Set new attribute value $img->setAttribute('src', $newSrc); } echo $dom->saveHTML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 29
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 29
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
filename:       /in/F9D31
function name:  (null)
number of ops:  34
compiled vars:  !0 = $html, !1 = $dom, !2 = $images, !3 = $img, !4 = $newSrc
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Cdiv+class%3D%22container%22%3E%0A+++%3Ch1%3EThe+Page+Title%3C%2Fh1%3E%0A%0A+++%3Cimg+src%3D%22MyImage.JPG%22+class%3D%22graphic%22+%2F%3E%0A%0A+++%3Cp%3ESome+body+copy...%3C%2Fp%3E%0A%0A+++%3Cimg+class%3D%22graphic%22+src%3D%22misc%2FSecondImage.JPG%22+%2F%3E%0A%3C%2Fdiv%3E'
   16     1        NEW                                              $6      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $6
   17     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        SEND_VAL_EX                                              8196
          7        DO_FCALL                                      0          
   20     8        INIT_METHOD_CALL                                         !1, 'getElementsByTagName'
          9        SEND_VAL_EX                                              'img'
         10        DO_FCALL                                      0  $10     
         11        ASSIGN                                                   !2, $10
   22    12      > FE_RESET_R                                       $12     !2, ->29
         13    > > FE_FETCH_R                                               $12, !3, ->29
   23    14    >   INIT_FCALL                                               'preg_replace_callback'
         15        SEND_VAL                                                 '%7E%5B%5E%2F%5D%2B%24%7E'
         16        DECLARE_LAMBDA_FUNCTION                          ~13     [0]
   26    17        SEND_VAL                                                 ~13
         18        INIT_METHOD_CALL                                         !3, 'getAttribute'
         19        SEND_VAL_EX                                              'src'
         20        DO_FCALL                                      0  $14     
         21        SEND_VAR                                                 $14
   23    22        DO_ICALL                                         $15     
         23        ASSIGN                                                   !4, $15
   28    24        INIT_METHOD_CALL                                         !3, 'setAttribute'
         25        SEND_VAL_EX                                              'src'
         26        SEND_VAR_EX                                              !4
         27        DO_FCALL                                      0          
   22    28      > JMP                                                      ->13
         29    >   FE_FREE                                                  $12
   31    30        INIT_METHOD_CALL                                         !1, 'saveHTML'
         31        DO_FCALL                                      0  $18     
         32        ECHO                                                     $18
         33      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/F9D31
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $match
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   25     1        INIT_FCALL                                               'strtolower'
          2        FETCH_DIM_R                                      ~1      !0, 0
          3        SEND_VAL                                                 ~1
          4        DO_ICALL                                         $2      
          5      > RETURN                                                   $2
   26     6*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.28 ms | 1008 KiB | 15 Q