3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = "<input type=\"text\">\n<img src=\"\"><a href=\"\"><button type=\"button\"></button><div id=\"some\"></div><p></p>"; var_dump(removeTags($str, array('img'))); /** * Strip only certain tags in the given HTML string * @return String */ function removeTags($html, $tags){ $existing_tags = getAllTagNames($html); $allowable_tags = '<'.implode('><', array_diff($existing_tags, $tags)).'>'; return strip_tags($html, $allowable_tags); } /** * Get a list of tag names in the provided HTML string * @return Array */ function getAllTagNames($html){ $tags = array(); $part = explode("<", $html); foreach($part as $tag){ $chunk = explode(" ", $tag); if(empty($chunk[0]) || $chunk[0][0] == "/") continue; $tag = trim($chunk[0], " >"); if(!in_array($tag, $tags)) $tags[] = $tag; } return $tags; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iaXNV
function name:  (null)
number of ops:  9
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, '%3Cinput+type%3D%22text%22%3E%0A%3Cimg+src%3D%22%22%3E%3Ca+href%3D%22%22%3E%3Cbutton+type%3D%22button%22%3E%3C%2Fbutton%3E%3Cdiv+id%3D%22some%22%3E%3C%2Fdiv%3E%3Cp%3E%3C%2Fp%3E'
    5     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL_BY_NAME                                       'removeTags'
          3        SEND_VAR_EX                                              !0
          4        SEND_VAL_EX                                              <array>
          5        DO_FCALL                                      0  $2      
          6        SEND_VAR                                                 $2
          7        DO_ICALL                                                 
   31     8      > RETURN                                                   1

Function removetags:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iaXNV
function name:  removeTags
number of ops:  23
compiled vars:  !0 = $html, !1 = $tags, !2 = $existing_tags, !3 = $allowable_tags
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   12     2        INIT_FCALL_BY_NAME                                       'getAllTagNames'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $4      
          5        ASSIGN                                                   !2, $4
   13     6        INIT_FCALL                                               'implode'
          7        SEND_VAL                                                 '%3E%3C'
          8        INIT_FCALL                                               'array_diff'
          9        SEND_VAR                                                 !2
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $6      
         12        SEND_VAR                                                 $6
         13        DO_ICALL                                         $7      
         14        CONCAT                                           ~8      '%3C', $7
         15        CONCAT                                           ~9      ~8, '%3E'
         16        ASSIGN                                                   !3, ~9
   14    17        INIT_FCALL                                               'strip_tags'
         18        SEND_VAR                                                 !0
         19        SEND_VAR                                                 !3
         20        DO_ICALL                                         $11     
         21      > RETURN                                                   $11
   15    22*     > RETURN                                                   null

End of function removetags

Function getalltagnames:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 37
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 37
Branch analysis from position: 9
2 jumps found. (Code = 47) Position 1 = 16, Position 2 = 20
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 22
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 36
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 36
Branch analysis from position: 20
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
filename:       /in/iaXNV
function name:  getAllTagNames
number of ops:  40
compiled vars:  !0 = $html, !1 = $tags, !2 = $part, !3 = $tag, !4 = $chunk
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
   22     1        ASSIGN                                                   !1, <array>
   23     2        INIT_FCALL                                               'explode'
          3        SEND_VAL                                                 '%3C'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $6      
          6        ASSIGN                                                   !2, $6
   24     7      > FE_RESET_R                                       $8      !2, ->37
          8    > > FE_FETCH_R                                               $8, !3, ->37
   25     9    >   INIT_FCALL                                               'explode'
         10        SEND_VAL                                                 '+'
         11        SEND_VAR                                                 !3
         12        DO_ICALL                                         $9      
         13        ASSIGN                                                   !4, $9
   26    14        ISSET_ISEMPTY_DIM_OBJ                         1  ~11     !4, 0
         15      > JMPNZ_EX                                         ~11     ~11, ->20
         16    >   FETCH_DIM_R                                      ~12     !4, 0
         17        FETCH_DIM_R                                      ~13     ~12, 0
         18        IS_EQUAL                                         ~14     ~13, '%2F'
         19        BOOL                                             ~11     ~14
         20    > > JMPZ                                                     ~11, ->22
         21    > > JMP                                                      ->8
   27    22    >   INIT_FCALL                                               'trim'
         23        FETCH_DIM_R                                      ~15     !4, 0
         24        SEND_VAL                                                 ~15
         25        SEND_VAL                                                 '+%3E'
         26        DO_ICALL                                         $16     
         27        ASSIGN                                                   !3, $16
   28    28        INIT_FCALL                                               'in_array'
         29        SEND_VAR                                                 !3
         30        SEND_VAR                                                 !1
         31        DO_ICALL                                         $18     
         32        BOOL_NOT                                         ~19     $18
         33      > JMPZ                                                     ~19, ->36
         34    >   ASSIGN_DIM                                               !1
         35        OP_DATA                                                  !3
   24    36    > > JMP                                                      ->8
         37    >   FE_FREE                                                  $8
   30    38      > RETURN                                                   !1
   31    39*     > RETURN                                                   null

End of function getalltagnames

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
181.89 ms | 1400 KiB | 27 Q