3v4l.org

run code in 300+ 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 = 70
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 70
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 70
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 70
filename:       /in/Cai40
function name:  (null)
number of ops:  75
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
-------------------------------------------------------------------------------------
   4     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      :144
         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     :136
         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, ->70
        16    > > FE_FETCH_R                                               $17, !4, ->70
  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        INIT_FCALL                                               'str_replace'
        46        SEND_VAL                                                 '%2Fthumbs%2F100%2F'
        47        SEND_VAL                                                 '%2F'
        48        SEND_VAR                                                 !6
        49        DO_ICALL                                         $27     
        50        CONCAT                                           ~28     '..', $27
        51        SEND_VAL_EX                                              ~28
        52        DO_FCALL                                      0          
  22    53        INIT_METHOD_CALL                                         !5, 'setAttribute'
        54        SEND_VAL_EX                                              'style'
        55        ROPE_INIT                                     3  ~31     'background%3A+url%28%27..'
        56        ROPE_ADD                                      1  ~31     ~31, !6
        57        ROPE_END                                      2  ~30     ~31, '%27%29%3B+-webkit-background-size%3Acover%3B+background-size%3Acover%3B'
        58        SEND_VAL_EX                                              ~30
        59        DO_FCALL                                      0          
  23    60        FETCH_OBJ_R                                      ~34     !4, 'parentNode'
        61        INIT_METHOD_CALL                                         ~34, 'insertBefore'
        62        SEND_VAR_EX                                              !5
        63        SEND_VAR_EX                                              !4
        64        DO_FCALL                                      0          
  24    65        FETCH_OBJ_R                                      ~36     !4, 'parentNode'
        66        INIT_METHOD_CALL                                         ~36, 'removeChild'
        67        SEND_VAR_EX                                              !4
        68        DO_FCALL                                      0          
  16    69      > JMP                                                      ->16
        70    >   FE_FREE                                                  $17
  26    71        INIT_METHOD_CALL                                         !1, 'saveHTML'
        72        DO_FCALL                                      0  $38     
        73        ECHO                                                     $38
        74      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
14.36 ms | 416 KiB | 7 Q