3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = '<div><img src="http://x.com" /><span>xyz</span><a href="http://example.com"><img src="http://example.com" /></a></div>'; $doc = new DOMDocument(); $doc->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $xpath = new DOMXpath($doc); $images = $xpath->query('//img'); foreach ($images as $image) { $div = $doc->createElement('div'); $div->setAttribute('class', 'demo'); $image->parentNode->replaceChild($div, $image); $div->appendChild($image); } echo $doc->saveHTML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 35
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 35
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
filename:       /in/RWO5E
function name:  (null)
number of ops:  40
compiled vars:  !0 = $html, !1 = $doc, !2 = $xpath, !3 = $images, !4 = $image, !5 = $div
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Cdiv%3E%3Cimg+src%3D%22http%3A%2F%2Fx.com%22+%2F%3E%3Cspan%3Exyz%3C%2Fspan%3E%3Ca+href%3D%22http%3A%2F%2Fexample.com%22%3E%3Cimg+src%3D%22http%3A%2F%2Fexample.com%22+%2F%3E%3C%2Fa%3E%3C%2Fdiv%3E'
    4     1        NEW                                              $7      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $7
    5     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        SEND_VAL_EX                                              8196
          7        DO_FCALL                                      0          
    6     8        NEW                                              $11     'DOMXpath'
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !2, $11
    7    12        INIT_METHOD_CALL                                         !2, 'query'
         13        SEND_VAL_EX                                              '%2F%2Fimg'
         14        DO_FCALL                                      0  $14     
         15        ASSIGN                                                   !3, $14
    8    16      > FE_RESET_R                                       $16     !3, ->35
         17    > > FE_FETCH_R                                               $16, !4, ->35
    9    18    >   INIT_METHOD_CALL                                         !1, 'createElement'
         19        SEND_VAL_EX                                              'div'
         20        DO_FCALL                                      0  $17     
         21        ASSIGN                                                   !5, $17
   10    22        INIT_METHOD_CALL                                         !5, 'setAttribute'
         23        SEND_VAL_EX                                              'class'
         24        SEND_VAL_EX                                              'demo'
         25        DO_FCALL                                      0          
   11    26        FETCH_OBJ_R                                      ~20     !4, 'parentNode'
         27        INIT_METHOD_CALL                                         ~20, 'replaceChild'
         28        SEND_VAR_EX                                              !5
         29        SEND_VAR_EX                                              !4
         30        DO_FCALL                                      0          
   12    31        INIT_METHOD_CALL                                         !5, 'appendChild'
         32        SEND_VAR_EX                                              !4
         33        DO_FCALL                                      0          
    8    34      > JMP                                                      ->17
         35    >   FE_FREE                                                  $16
   14    36        INIT_METHOD_CALL                                         !1, 'saveHTML'
         37        DO_FCALL                                      0  $23     
         38        ECHO                                                     $23
         39      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.56 ms | 1004 KiB | 13 Q