3v4l.org

run code in 300+ PHP versions simultaneously
<?php $content = ' <img alt="this is super nice image with lable 4" src="5.jpg" style="height:560px; width:840px"> <img alt="Description 2" src="1.jpg" style="height:560px; width:840px" class="dupa" data-label-class="label-class"> <img src="1.jpg" style="height:560px; width:840px" class="dupa" data-label-class="label-class"> '; $content = html_entity_decode($content, ENT_QUOTES, 'UTF-8'); $doc = new DOMDocument(); $doc->loadHTML($content); $tags = $doc->getElementsByTagName('img'); foreach ($tags as $tag) { // get value of an attribute $alt = $tag->getAttribute('alt'); if (!empty($alt)) { $class = $tag->getAttribute('class'); if (!empty($class)) { $class .= " picla"; } else { $class = "picla"; } $tag->setAttribute('class', $class); } } $content = $doc->saveHTML(); echo $content;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 41
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 41
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 40
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 35
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 40
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
filename:       /in/46Hra
function name:  (null)
number of ops:  47
compiled vars:  !0 = $content, !1 = $doc, !2 = $tags, !3 = $tag, !4 = $alt, !5 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%0A%3Cimg+alt%3D%22this+is+super+nice+image+with+lable+4%22+src%3D%225.jpg%22+style%3D%22height%3A560px%3B+width%3A840px%22%3E%0A%3Cimg+alt%3D%22Description+2%22+src%3D%221.jpg%22+style%3D%22height%3A560px%3B+width%3A840px%22+class%3D%22dupa%22+data-label-class%3D%22label-class%22%3E%0A%3Cimg+src%3D%221.jpg%22+style%3D%22height%3A560px%3B+width%3A840px%22+class%3D%22dupa%22+data-label-class%3D%22label-class%22%3E%0A'
    9     1        INIT_FCALL                                               'html_entity_decode'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 3
          4        SEND_VAL                                                 'UTF-8'
          5        DO_ICALL                                         $7      
          6        ASSIGN                                                   !0, $7
   11     7        NEW                                              $9      'DOMDocument'
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !1, $9
   12    10        INIT_METHOD_CALL                                         !1, 'loadHTML'
         11        SEND_VAR_EX                                              !0
         12        DO_FCALL                                      0          
   13    13        INIT_METHOD_CALL                                         !1, 'getElementsByTagName'
         14        SEND_VAL_EX                                              'img'
         15        DO_FCALL                                      0  $13     
         16        ASSIGN                                                   !2, $13
   15    17      > FE_RESET_R                                       $15     !2, ->41
         18    > > FE_FETCH_R                                               $15, !3, ->41
   17    19    >   INIT_METHOD_CALL                                         !3, 'getAttribute'
         20        SEND_VAL_EX                                              'alt'
         21        DO_FCALL                                      0  $16     
         22        ASSIGN                                                   !4, $16
   19    23        ISSET_ISEMPTY_CV                                 ~18     !4
         24        BOOL_NOT                                         ~19     ~18
         25      > JMPZ                                                     ~19, ->40
   20    26    >   INIT_METHOD_CALL                                         !3, 'getAttribute'
         27        SEND_VAL_EX                                              'class'
         28        DO_FCALL                                      0  $20     
         29        ASSIGN                                                   !5, $20
   21    30        ISSET_ISEMPTY_CV                                 ~22     !5
         31        BOOL_NOT                                         ~23     ~22
         32      > JMPZ                                                     ~23, ->35
   22    33    >   ASSIGN_OP                                     8          !5, '+picla'
   21    34      > JMP                                                      ->36
   24    35    >   ASSIGN                                                   !5, 'picla'
   26    36    >   INIT_METHOD_CALL                                         !3, 'setAttribute'
         37        SEND_VAL_EX                                              'class'
         38        SEND_VAR_EX                                              !5
         39        DO_FCALL                                      0          
   15    40    > > JMP                                                      ->18
         41    >   FE_FREE                                                  $15
   30    42        INIT_METHOD_CALL                                         !1, 'saveHTML'
         43        DO_FCALL                                      0  $27     
         44        ASSIGN                                                   !0, $27
   32    45        ECHO                                                     !0
   33    46      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.67 ms | 949 KiB | 14 Q