3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <html> <body> <div>foo</div> <script>console.log('bar');</script> <script>var foo = 5;</script> <script>console.log('leave me alone');</script> </body> </html> HTML; $doc = new \DOMDocument(); $doc->loadHTML($html, LIBXML_HTML_NODEFDTD); $xpath = new \DOMXPath($doc); foreach ($xpath->query('//script[contains(text(), \'foo\') or contains(text(), \'bar\')]') as $script_tag) { $script_tag->parentNode->removeChild($script_tag); } echo $doc->saveHTML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 22
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 22
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/dHGDt
function name:  (null)
number of ops:  27
compiled vars:  !0 = $html, !1 = $doc, !2 = $xpath, !3 = $script_tag
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Chtml%3E%0A++%3Cbody%3E%0A++++%3Cdiv%3Efoo%3C%2Fdiv%3E%0A++++%3Cscript%3Econsole.log%28%27bar%27%29%3B%3C%2Fscript%3E%0A++++%3Cscript%3Evar+foo+%3D+5%3B%3C%2Fscript%3E%0A++++%3Cscript%3Econsole.log%28%27leave+me+alone%27%29%3B%3C%2Fscript%3E%0A++%3C%2Fbody%3E%0A%3C%2Fhtml%3E'
   14     1        NEW                                              $5      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $5
   15     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        SEND_VAL_EX                                              4
          7        DO_FCALL                                      0          
   17     8        NEW                                              $9      'DOMXPath'
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !2, $9
   18    12        INIT_METHOD_CALL                                         !2, 'query'
         13        SEND_VAL_EX                                              '%2F%2Fscript%5Bcontains%28text%28%29%2C+%27foo%27%29+or+contains%28text%28%29%2C+%27bar%27%29%5D'
         14        DO_FCALL                                      0  $12     
         15      > FE_RESET_R                                       $13     $12, ->22
         16    > > FE_FETCH_R                                               $13, !3, ->22
   19    17    >   FETCH_OBJ_R                                      ~14     !3, 'parentNode'
         18        INIT_METHOD_CALL                                         ~14, 'removeChild'
         19        SEND_VAR_EX                                              !3
         20        DO_FCALL                                      0          
   18    21      > JMP                                                      ->16
         22    >   FE_FREE                                                  $13
   22    23        INIT_METHOD_CALL                                         !1, 'saveHTML'
         24        DO_FCALL                                      0  $16     
         25        ECHO                                                     $16
         26      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.96 ms | 1399 KiB | 13 Q