3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <html> <body> <div class="regular-box">DIV 0</div> <div class="comments-box">DIV 1</div> <div class="heycomments-box">DIV 2</div> <div class="sdfcomments-box">DIV 3</div> <div class="sdgsdgcomments-boxsdfdfh">DIV 4</div> </body> </html> HTML; $dom = new DOMDocument; $dom->loadHTML($html, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED); $xp = new DOMXPath($dom); // get the node list of div nodes with "target" class $spanNodeList = $xp->query('//div[contains(@class, "comments-box")]'); foreach ($spanNodeList as $spanNode) { $spanNode->parentNode->replaceChild($spanNode->firstChild, $spanNode); } echo $dom->saveHTML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 26
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 26
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/040Pe
function name:  (null)
number of ops:  31
compiled vars:  !0 = $html, !1 = $dom, !2 = $xp, !3 = $spanNodeList, !4 = $spanNode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Chtml%3E%0A%3Cbody%3E%0A%3Cdiv+class%3D%22regular-box%22%3EDIV+0%3C%2Fdiv%3E%0A%3Cdiv+class%3D%22comments-box%22%3EDIV+1%3C%2Fdiv%3E%0A%3Cdiv+class%3D%22heycomments-box%22%3EDIV+2%3C%2Fdiv%3E%0A%3Cdiv+class%3D%22sdfcomments-box%22%3EDIV+3%3C%2Fdiv%3E%0A%3Cdiv+class%3D%22sdgsdgcomments-boxsdfdfh%22%3EDIV+4%3C%2Fdiv%3E%0A%3C%2Fbody%3E%0A%3C%2Fhtml%3E'
   15     1        NEW                                              $6      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $6
   16     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        SEND_VAL_EX                                              8196
          7        DO_FCALL                                      0          
   17     8        NEW                                              $10     'DOMXPath'
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !2, $10
   20    12        INIT_METHOD_CALL                                         !2, 'query'
         13        SEND_VAL_EX                                              '%2F%2Fdiv%5Bcontains%28%40class%2C+%22comments-box%22%29%5D'
         14        DO_FCALL                                      0  $13     
         15        ASSIGN                                                   !3, $13
   22    16      > FE_RESET_R                                       $15     !3, ->26
         17    > > FE_FETCH_R                                               $15, !4, ->26
   23    18    >   FETCH_OBJ_R                                      ~16     !4, 'parentNode'
         19        INIT_METHOD_CALL                                         ~16, 'replaceChild'
         20        CHECK_FUNC_ARG                                           
         21        FETCH_OBJ_FUNC_ARG                               $17     !4, 'firstChild'
         22        SEND_FUNC_ARG                                            $17
         23        SEND_VAR_EX                                              !4
         24        DO_FCALL                                      0          
   22    25      > JMP                                                      ->17
         26    >   FE_FREE                                                  $15
   26    27        INIT_METHOD_CALL                                         !1, 'saveHTML'
         28        DO_FCALL                                      0  $19     
         29        ECHO                                                     $19
         30      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.12 ms | 1395 KiB | 13 Q