3v4l.org

run code in 500+ PHP versions simultaneously
<?php $html = <<<HTML <body> <img src="http://example/img/product/name/thumbs/100/img.jpg" alt="lol" width="100" height="100" caption="false" class="popup-img left" /> </body> HTML; $dom = new DOMDocument(); $dom->loadHTML($html); $xpath = new DOMXPath($dom); $nodes = $xpath->query('//img[contains(@class, "popup-img")]'); foreach($nodes as $node) { $a = $dom->createElement('a'); $a->setAttribute('class', $node->getAttribute("class")); $a->setAttribute('title', $node->getAttribute("alt")); $href = parse_url($node->getAttribute("src"), PHP_URL_PATH); $a->setAttribute('href', '..' . str_replace('/thumbs/100/', '/', $href)); $a->setAttribute('style', "background: url('..$href'); -webkit-background-size:cover; background-size:cover;"); $node->parentNode->insertBefore($a, $node); $node->parentNode->removeChild($node); } echo $dom->saveHTML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 67
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 67
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 67
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 67
filename:       /in/Cai40
function name:  (null)
number of ops:  72
compiled vars:  !0 = $html, !1 = $dom, !2 = $xpath, !3 = $nodes, !4 = $node, !5 = $a, !6 = $href
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '%3Cbody%3E%0A%3Cimg+src%3D%22http%3A%2F%2Fexample%2Fimg%2Fproduct%2Fname%2Fthumbs%2F100%2Fimg.jpg%22+%0Aalt%3D%22lol%22+width%3D%22100%22+height%3D%22100%22+caption%3D%22false%22+class%3D%22popup-img+left%22+%2F%3E%0A%3C%2Fbody%3E'
   10     1        NEW                                                  $8      'DOMDocument'
          2        DO_FCALL                                          0          
          3        ASSIGN                                                       !1, $8
   11     4        INIT_METHOD_CALL                                             !1, 'loadHTML'
          5        SEND_VAR_EX                                                  !0
          6        DO_FCALL                                          0          
   13     7        NEW                                                  $12     'DOMXPath'
          8        SEND_VAR_EX                                                  !1
          9        DO_FCALL                                          0          
         10        ASSIGN                                                       !2, $12
   14    11        INIT_METHOD_CALL                                             !2, 'query'
         12        SEND_VAL_EX                                                  '%2F%2Fimg%5Bcontains%28%40class%2C+%22popup-img%22%29%5D'
         13        DO_FCALL                                          0  $15     
         14        ASSIGN                                                       !3, $15
   16    15      > FE_RESET_R                                           $17     !3, ->67
         16    > > FE_FETCH_R                                                   $17, !4, ->67
   17    17    >   INIT_METHOD_CALL                                             !1, 'createElement'
         18        SEND_VAL_EX                                                  'a'
         19        DO_FCALL                                          0  $18     
         20        ASSIGN                                                       !5, $18
   18    21        INIT_METHOD_CALL                                             !5, 'setAttribute'
         22        SEND_VAL_EX                                                  'class'
         23        INIT_METHOD_CALL                                             !4, 'getAttribute'
         24        SEND_VAL_EX                                                  'class'
         25        DO_FCALL                                          0  $20     
         26        SEND_VAR_NO_REF_EX                                           $20
         27        DO_FCALL                                          0          
   19    28        INIT_METHOD_CALL                                             !5, 'setAttribute'
         29        SEND_VAL_EX                                                  'title'
         30        INIT_METHOD_CALL                                             !4, 'getAttribute'
         31        SEND_VAL_EX                                                  'alt'
         32        DO_FCALL                                          0  $22     
         33        SEND_VAR_NO_REF_EX                                           $22
         34        DO_FCALL                                          0          
   20    35        INIT_FCALL                                                   'parse_url'
         36        INIT_METHOD_CALL                                             !4, 'getAttribute'
         37        SEND_VAL_EX                                                  'src'
         38        DO_FCALL                                          0  $24     
         39        SEND_VAR                                                     $24
         40        SEND_VAL                                                     5
         41        DO_ICALL                                             $25     
         42        ASSIGN                                                       !6, $25
   21    43        INIT_METHOD_CALL                                             !5, 'setAttribute'
         44        SEND_VAL_EX                                                  'href'
         45        FRAMELESS_ICALL_3                str_replace         ~27     '%2Fthumbs%2F100%2F', '%2F'
         46        OP_DATA                                                      !6
         47        CONCAT                                               ~28     '..', ~27
         48        SEND_VAL_EX                                                  ~28
         49        DO_FCALL                                          0          
   22    50        INIT_METHOD_CALL                                             !5, 'setAttribute'
         51        SEND_VAL_EX                                                  'style'
         52        ROPE_INIT                                         3  ~31     'background%3A+url%28%27..'
         53        ROPE_ADD                                          1  ~31     ~31, !6
         54        ROPE_END                                          2  ~30     ~31, '%27%29%3B+-webkit-background-size%3Acover%3B+background-size%3Acover%3B'
         55        SEND_VAL_EX                                                  ~30
         56        DO_FCALL                                          0          
   23    57        FETCH_OBJ_R                                          ~34     !4, 'parentNode'
         58        INIT_METHOD_CALL                                             ~34, 'insertBefore'
         59        SEND_VAR_EX                                                  !5
         60        SEND_VAR_EX                                                  !4
         61        DO_FCALL                                          0          
   24    62        FETCH_OBJ_R                                          ~36     !4, 'parentNode'
         63        INIT_METHOD_CALL                                             ~36, 'removeChild'
         64        SEND_VAR_EX                                                  !4
         65        DO_FCALL                                          0          
   16    66      > JMP                                                          ->16
         67    >   FE_FREE                                                      $17
   26    68        INIT_METHOD_CALL                                             !1, 'saveHTML'
         69        DO_FCALL                                          0  $38     
         70        ECHO                                                         $38
         71      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
230.4 ms | 2179 KiB | 16 Q