3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <!DOCTYPE HTML> <html> <span class="unwrap_me"><i><span class="foo">Lorem</span></i><span class="foo">ipsum</span></span> </html> HTML; $dom = new DOMDocument(); $dom->loadHTML($html); $spans = iterator_to_array($dom->getElementsByTagName('span')->getIterator()); foreach ($spans as $span) { if ('unwrap_me' === $span->getAttribute('class')) { $fragment = $dom->createDocumentFragment(); $fragment->append(...$span->childNodes); $span->parentNode?->replaceChild($fragment, $span); } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 38
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 38
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 37
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 37
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
filename:       /in/iPl83
function name:  (null)
number of ops:  40
compiled vars:  !0 = $html, !1 = $dom, !2 = $spans, !3 = $span, !4 = $fragment
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3C%21DOCTYPE+HTML%3E%0A%3Chtml%3E%0A%3Cspan+class%3D%22unwrap_me%22%3E%3Ci%3E%3Cspan+class%3D%22foo%22%3ELorem%3C%2Fspan%3E%3C%2Fi%3E%3Cspan+class%3D%22foo%22%3Eipsum%3C%2Fspan%3E%3C%2Fspan%3E%0A%3C%2Fhtml%3E'
   10     1        NEW                                              $6      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $6
   11     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   13     7        INIT_FCALL                                               'iterator_to_array'
          8        INIT_METHOD_CALL                                         !1, 'getElementsByTagName'
          9        SEND_VAL_EX                                              'span'
         10        DO_FCALL                                      0  $10     
         11        INIT_METHOD_CALL                                         $10, 'getIterator'
         12        DO_FCALL                                      0  $11     
         13        SEND_VAR                                                 $11
         14        DO_ICALL                                         $12     
         15        ASSIGN                                                   !2, $12
   14    16      > FE_RESET_R                                       $14     !2, ->38
         17    > > FE_FETCH_R                                               $14, !3, ->38
   15    18    >   INIT_METHOD_CALL                                         !3, 'getAttribute'
         19        SEND_VAL_EX                                              'class'
         20        DO_FCALL                                      0  $15     
         21        IS_IDENTICAL                                             $15, 'unwrap_me'
         22      > JMPZ                                                     ~16, ->37
   16    23    >   INIT_METHOD_CALL                                         !1, 'createDocumentFragment'
         24        DO_FCALL                                      0  $17     
         25        ASSIGN                                                   !4, $17
   17    26        INIT_METHOD_CALL                                         !4, 'append'
         27        FETCH_OBJ_R                                      ~19     !3, 'childNodes'
         28        SEND_UNPACK                                              ~19
         29        CHECK_UNDEF_ARGS                                         
         30        DO_FCALL                                      1          
   18    31        FETCH_OBJ_R                                      ~21     !3, 'parentNode'
         32        JMP_NULL                                         $22     ~21
         33        INIT_METHOD_CALL                                         ~21, 'replaceChild'
         34        SEND_VAR_EX                                              !4
         35        SEND_VAR_EX                                              !3
         36        DO_FCALL                                      0          
   14    37    > > JMP                                                      ->17
         38    >   FE_FREE                                                  $14
   20    39      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.52 ms | 1015 KiB | 14 Q