3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = <<<HTML <!doctype html> <html> <body> text to keep <span xxx="xxxx"><span xxx="xxx">unwanted text</span> unwanted text </span> text to keep </body> </html> HTML; $doc = new DOMDocument(); $doc->loadHTML($str); $xpath = new DOMXPath($doc); foreach($xpath->evaluate("//span") as $node) { echo 'Removing: '.$node->nodeValue."<br>"; $node->parentNode->removeChild($node); } $output = $doc->saveHTML(); echo htmlspecialchars($output);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 25
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 25
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/6m0e2
function name:  (null)
number of ops:  34
compiled vars:  !0 = $str, !1 = $doc, !2 = $xpath, !3 = $node, !4 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3C%21doctype+html%3E%0A%3Chtml%3E%0A%3Cbody%3E%0Atext+to+keep+%3Cspan+xxx%3D%22xxxx%22%3E%3Cspan+xxx%3D%22xxx%22%3Eunwanted+text%3C%2Fspan%3E+unwanted+text+%3C%2Fspan%3E+text+to+keep%0A%3C%2Fbody%3E%0A%3C%2Fhtml%3E'
   11     1        NEW                                              $6      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $6
   12     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   13     7        NEW                                              $10     'DOMXPath'
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !2, $10
   15    11        INIT_METHOD_CALL                                         !2, 'evaluate'
         12        SEND_VAL_EX                                              '%2F%2Fspan'
         13        DO_FCALL                                      0  $13     
         14      > FE_RESET_R                                       $14     $13, ->25
         15    > > FE_FETCH_R                                               $14, !3, ->25
   16    16    >   FETCH_OBJ_R                                      ~15     !3, 'nodeValue'
         17        CONCAT                                           ~16     'Removing%3A+', ~15
         18        CONCAT                                           ~17     ~16, '%3Cbr%3E'
         19        ECHO                                                     ~17
   17    20        FETCH_OBJ_R                                      ~18     !3, 'parentNode'
         21        INIT_METHOD_CALL                                         ~18, 'removeChild'
         22        SEND_VAR_EX                                              !3
         23        DO_FCALL                                      0          
   15    24      > JMP                                                      ->15
         25    >   FE_FREE                                                  $14
   19    26        INIT_METHOD_CALL                                         !1, 'saveHTML'
         27        DO_FCALL                                      0  $20     
         28        ASSIGN                                                   !4, $20
   20    29        INIT_FCALL                                               'htmlspecialchars'
         30        SEND_VAR                                                 !4
         31        DO_ICALL                                         $22     
         32        ECHO                                                     $22
         33      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.12 ms | 998 KiB | 14 Q