3v4l.org

run code in 300+ PHP versions simultaneously
<?php function remove_script_tags($html){ $dom = new DOMDocument(); $dom->loadHTML($html); $script = $dom->getElementsByTagName('script'); $remove = []; foreach($script as $item){ $remove[] = $item; } foreach ($remove as $item){ $item->parentNode->removeChild($item); } $html = $dom->saveHTML(); return $html; } $s = []; $s[] = "hey buddy what's up script"; $s[] = "Hi Friend <script>alert('hello world');</script>"; $s[] = "<script src=\"http://jquery.com\">joyjoy</script>happy"; foreach($s as $t){ echo $t.' ==> '.remove_script_tags($t)."\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 17
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 17
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/1TNHP
function name:  (null)
number of ops:  19
compiled vars:  !0 = $s, !1 = $t
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   ASSIGN                                                   !0, <array>
   23     1        ASSIGN_DIM                                               !0
          2        OP_DATA                                                  'hey+buddy+what%27s+up+script'
   24     3        ASSIGN_DIM                                               !0
          4        OP_DATA                                                  'Hi+Friend+%3Cscript%3Ealert%28%27hello+world%27%29%3B%3C%2Fscript%3E'
   25     5        ASSIGN_DIM                                               !0
          6        OP_DATA                                                  '%3Cscript+src%3D%22http%3A%2F%2Fjquery.com%22%3Ejoyjoy%3C%2Fscript%3Ehappy'
   27     7      > FE_RESET_R                                       $6      !0, ->17
          8    > > FE_FETCH_R                                               $6, !1, ->17
   28     9    >   CONCAT                                           ~7      !1, '+%3D%3D%3E+'
         10        INIT_FCALL                                               'remove_script_tags'
         11        SEND_VAR                                                 !1
         12        DO_FCALL                                      0  $8      
         13        CONCAT                                           ~9      ~7, $8
         14        CONCAT                                           ~10     ~9, '%0A'
         15        ECHO                                                     ~10
   27    16      > JMP                                                      ->8
         17    >   FE_FREE                                                  $6
   29    18      > RETURN                                                   1

Function remove_script_tags:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 17
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 17
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 17
2 jumps found. (Code = 77) Position 1 = 19, Position 2 = 25
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 25
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
Branch analysis from position: 17
filename:       /in/1TNHP
function name:  remove_script_tags
number of ops:  31
compiled vars:  !0 = $html, !1 = $dom, !2 = $script, !3 = $remove, !4 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        NEW                                              $5      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $5
    5     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
    6     7        INIT_METHOD_CALL                                         !1, 'getElementsByTagName'
          8        SEND_VAL_EX                                              'script'
          9        DO_FCALL                                      0  $9      
         10        ASSIGN                                                   !2, $9
    8    11        ASSIGN                                                   !3, <array>
    9    12      > FE_RESET_R                                       $12     !2, ->17
         13    > > FE_FETCH_R                                               $12, !4, ->17
   10    14    >   ASSIGN_DIM                                               !3
         15        OP_DATA                                                  !4
    9    16      > JMP                                                      ->13
         17    >   FE_FREE                                                  $12
   13    18      > FE_RESET_R                                       $14     !3, ->25
         19    > > FE_FETCH_R                                               $14, !4, ->25
   14    20    >   FETCH_OBJ_R                                      ~15     !4, 'parentNode'
         21        INIT_METHOD_CALL                                         ~15, 'removeChild'
         22        SEND_VAR_EX                                              !4
         23        DO_FCALL                                      0          
   13    24      > JMP                                                      ->19
         25    >   FE_FREE                                                  $14
   17    26        INIT_METHOD_CALL                                         !1, 'saveHTML'
         27        DO_FCALL                                      0  $17     
         28        ASSIGN                                                   !0, $17
   18    29      > RETURN                                                   !0
   19    30*     > RETURN                                                   null

End of function remove_script_tags

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
240.85 ms | 1418 KiB | 15 Q