3v4l.org

run code in 300+ PHP versions simultaneously
<?php function stripTagFormatting(DOMText $textNode) { $css = []; $existingStyles = ''; $currentNode = $textNode->parentNode; do { switch (strtolower($currentNode->tagName)) { case 'font': if ($currentNode->hasAttribute('color') && !isset($css['color'])) { $css['color'] = $currentNode->getAttribute('color'); } if ($currentNode->hasAttribute('size') && !isset($css['font-size'])) { $css['font-size'] = $currentNode->getAttribute('size') . 'px'; } if ($currentNode->hasAttribute('face') && !isset($css['font-family'])) { $css['font-family'] = $currentNode->getAttribute('face'); } break; case 'b': if (!isset($css['font-weight'])) { $css['font-weight'] = 'bold'; } break; case 'i': if (!isset($css['font-style'])) { $css['font-style'] = 'italic'; } break; default: if ($currentNode->hasAttribute('style')) { $existingStyles = $currentNode->getAttribute('style'); } break 2; } } while($currentNode->parentNode->childNodes->length == 1 && $currentNode = $currentNode->parentNode); var_dump($currentNode->tagName, $css); } $html = '<FONT FACE="League" SIZE="15" COLOR="#000000"><font COLOR="#ff00ff" SIZE="18"><b><font SIZE="23"><font SIZE="27"><font SIZE="23"><font SIZE="18"><font SIZE="23">Moet Flip make-up dragen? <br />Stem mee in de poll!!</font></font></font></font></font></b></font><br /></FONT>'; $dom = new DOMDOcument(); $dom->loadHTML($html); $xpath = new DOMXPath($dom); $nodes = $xpath->evaluate("/html/body//text()"); foreach ($nodes as $node) { stripTagFormatting($node); } var_dump($dom->saveHTML());
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 21
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 21
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/LUMED
function name:  (null)
number of ops:  28
compiled vars:  !0 = $html, !1 = $dom, !2 = $xpath, !3 = $nodes, !4 = $node
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   ASSIGN                                                   !0, '%3CFONT+FACE%3D%22League%22+SIZE%3D%2215%22+COLOR%3D%22%23000000%22%3E%3Cfont+COLOR%3D%22%23ff00ff%22+SIZE%3D%2218%22%3E%3Cb%3E%3Cfont+SIZE%3D%2223%22%3E%3Cfont+SIZE%3D%2227%22%3E%3Cfont+SIZE%3D%2223%22%3E%3Cfont+SIZE%3D%2218%22%3E%3Cfont+SIZE%3D%2223%22%3EMoet+Flip+make-up+dragen%3F++%3Cbr+%2F%3EStem+mee+in+de+poll%21%21%3C%2Ffont%3E%3C%2Ffont%3E%3C%2Ffont%3E%3C%2Ffont%3E%3C%2Ffont%3E%3C%2Fb%3E%3C%2Ffont%3E%3Cbr+%2F%3E%3C%2FFONT%3E'
   47     1        NEW                                              $6      'DOMDOcument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $6
   48     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   50     7        NEW                                              $10     'DOMXPath'
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !2, $10
   52    11        INIT_METHOD_CALL                                         !2, 'evaluate'
         12        SEND_VAL_EX                                              '%2Fhtml%2Fbody%2F%2Ftext%28%29'
         13        DO_FCALL                                      0  $13     
         14        ASSIGN                                                   !3, $13
   54    15      > FE_RESET_R                                       $15     !3, ->21
         16    > > FE_FETCH_R                                               $15, !4, ->21
   55    17    >   INIT_FCALL                                               'striptagformatting'
         18        SEND_VAR                                                 !4
         19        DO_FCALL                                      0          
   54    20      > JMP                                                      ->16
         21    >   FE_FREE                                                  $15
   58    22        INIT_FCALL                                               'var_dump'
         23        INIT_METHOD_CALL                                         !1, 'saveHTML'
         24        DO_FCALL                                      0  $17     
         25        SEND_VAR                                                 $17
         26        DO_ICALL                                                 
         27      > RETURN                                                   1

Function striptagformatting:
Finding entry points
Branch analysis from position: 0
5 jumps found. (Code = 188) Position 1 = 17, Position 2 = 58, Position 3 = 64, Position 4 = 70, Position 5 = 10
Branch analysis from position: 17
2 jumps found. (Code = 46) Position 1 = 21, Position 2 = 24
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 30
Branch analysis from position: 25
2 jumps found. (Code = 46) Position 1 = 34, Position 2 = 37
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 44
Branch analysis from position: 38
2 jumps found. (Code = 46) Position 1 = 48, Position 2 = 51
Branch analysis from position: 48
2 jumps found. (Code = 43) Position 1 = 52, Position 2 = 57
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 80
Branch analysis from position: 80
2 jumps found. (Code = 46) Position 1 = 86, Position 2 = 89
Branch analysis from position: 86
2 jumps found. (Code = 44) Position 1 = 90, Position 2 = 5
Branch analysis from position: 90
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
Branch analysis from position: 89
Branch analysis from position: 57
Branch analysis from position: 51
Branch analysis from position: 44
Branch analysis from position: 37
Branch analysis from position: 30
Branch analysis from position: 24
Branch analysis from position: 58
2 jumps found. (Code = 43) Position 1 = 61, Position 2 = 63
Branch analysis from position: 61
1 jumps found. (Code = 42) Position 1 = 80
Branch analysis from position: 80
Branch analysis from position: 63
Branch analysis from position: 64
2 jumps found. (Code = 43) Position 1 = 67, Position 2 = 69
Branch analysis from position: 67
1 jumps found. (Code = 42) Position 1 = 80
Branch analysis from position: 80
Branch analysis from position: 69
Branch analysis from position: 70
2 jumps found. (Code = 43) Position 1 = 74, Position 2 = 78
Branch analysis from position: 74
1 jumps found. (Code = 42) Position 1 = 90
Branch analysis from position: 90
Branch analysis from position: 78
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 17
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 58
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 64
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 70
Branch analysis from position: 70
Branch analysis from position: 64
Branch analysis from position: 58
Branch analysis from position: 17
filename:       /in/LUMED
function name:  stripTagFormatting
number of ops:  96
compiled vars:  !0 = $textNode, !1 = $css, !2 = $existingStyles, !3 = $currentNode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, <array>
    5     2        ASSIGN                                                   !2, ''
    7     3        FETCH_OBJ_R                                      ~6      !0, 'parentNode'
          4        ASSIGN                                                   !3, ~6
    9     5    >   INIT_FCALL                                               'strtolower'
          6        FETCH_OBJ_R                                      ~8      !3, 'tagName'
          7        SEND_VAL                                                 ~8
          8        DO_ICALL                                         $9      
          9      > SWITCH_STRING                                            $9, [ 'font':->17, 'b':->58, 'i':->64, ], ->70
   10    10    >   CASE                                                     $9, 'font'
         11      > JMPNZ                                                    ~10, ->17
   22    12    >   CASE                                                     $9, 'b'
         13      > JMPNZ                                                    ~10, ->58
   28    14    >   CASE                                                     $9, 'i'
         15      > JMPNZ                                                    ~10, ->64
         16    > > JMP                                                      ->70
   11    17    >   INIT_METHOD_CALL                                         !3, 'hasAttribute'
         18        SEND_VAL_EX                                              'color'
         19        DO_FCALL                                      0  $11     
         20      > JMPZ_EX                                          ~12     $11, ->24
         21    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~13     !1, 'color'
         22        BOOL_NOT                                         ~14     ~13
         23        BOOL                                             ~12     ~14
         24    > > JMPZ                                                     ~12, ->30
   12    25    >   INIT_METHOD_CALL                                         !3, 'getAttribute'
         26        SEND_VAL_EX                                              'color'
         27        DO_FCALL                                      0  $16     
         28        ASSIGN_DIM                                               !1, 'color'
         29        OP_DATA                                                  $16
   14    30    >   INIT_METHOD_CALL                                         !3, 'hasAttribute'
         31        SEND_VAL_EX                                              'size'
         32        DO_FCALL                                      0  $17     
         33      > JMPZ_EX                                          ~18     $17, ->37
         34    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~19     !1, 'font-size'
         35        BOOL_NOT                                         ~20     ~19
         36        BOOL                                             ~18     ~20
         37    > > JMPZ                                                     ~18, ->44
   15    38    >   INIT_METHOD_CALL                                         !3, 'getAttribute'
         39        SEND_VAL_EX                                              'size'
         40        DO_FCALL                                      0  $22     
         41        CONCAT                                           ~23     $22, 'px'
         42        ASSIGN_DIM                                               !1, 'font-size'
         43        OP_DATA                                                  ~23
   17    44    >   INIT_METHOD_CALL                                         !3, 'hasAttribute'
         45        SEND_VAL_EX                                              'face'
         46        DO_FCALL                                      0  $24     
         47      > JMPZ_EX                                          ~25     $24, ->51
         48    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~26     !1, 'font-family'
         49        BOOL_NOT                                         ~27     ~26
         50        BOOL                                             ~25     ~27
         51    > > JMPZ                                                     ~25, ->57
   18    52    >   INIT_METHOD_CALL                                         !3, 'getAttribute'
         53        SEND_VAL_EX                                              'face'
         54        DO_FCALL                                      0  $29     
         55        ASSIGN_DIM                                               !1, 'font-family'
         56        OP_DATA                                                  $29
   20    57    > > JMP                                                      ->80
   23    58    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~30     !1, 'font-weight'
         59        BOOL_NOT                                         ~31     ~30
         60      > JMPZ                                                     ~31, ->63
   24    61    >   ASSIGN_DIM                                               !1, 'font-weight'
         62        OP_DATA                                                  'bold'
   26    63    > > JMP                                                      ->80
   29    64    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~33     !1, 'font-style'
         65        BOOL_NOT                                         ~34     ~33
         66      > JMPZ                                                     ~34, ->69
   30    67    >   ASSIGN_DIM                                               !1, 'font-style'
         68        OP_DATA                                                  'italic'
   32    69    > > JMP                                                      ->80
   35    70    >   INIT_METHOD_CALL                                         !3, 'hasAttribute'
         71        SEND_VAL_EX                                              'style'
         72        DO_FCALL                                      0  $36     
         73      > JMPZ                                                     $36, ->78
   36    74    >   INIT_METHOD_CALL                                         !3, 'getAttribute'
         75        SEND_VAL_EX                                              'style'
         76        DO_FCALL                                      0  $37     
         77        ASSIGN                                                   !2, $37
   38    78    >   FREE                                                     $9
         79      > JMP                                                      ->90
         80    >   FREE                                                     $9
   40    81        FETCH_OBJ_R                                      ~39     !3, 'parentNode'
         82        FETCH_OBJ_R                                      ~40     ~39, 'childNodes'
         83        FETCH_OBJ_R                                      ~41     ~40, 'length'
         84        IS_EQUAL                                         ~42     ~41, 1
         85      > JMPZ_EX                                          ~42     ~42, ->89
         86    >   FETCH_OBJ_R                                      ~43     !3, 'parentNode'
         87        ASSIGN                                           ~44     !3, ~43
         88        BOOL                                             ~42     ~44
         89    > > JMPNZ                                                    ~42, ->5
   42    90    >   INIT_FCALL                                               'var_dump'
         91        FETCH_OBJ_R                                      ~45     !3, 'tagName'
         92        SEND_VAL                                                 ~45
         93        SEND_VAR                                                 !1
         94        DO_ICALL                                                 
   43    95      > RETURN                                                   null

End of function striptagformatting

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.85 ms | 1411 KiB | 18 Q