3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function getColor($domnode) { while($domnode->parentNode) { if ($domnode->parentNode->getAttribute('color')) { return $domnode->parentNode->getAttribute('color'); } } } $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) { $color = getColor($node); var_dump($color); if ($color) { $span = $document->createElement('span'); $span->setAttribute('style', 'color: ' . $color . ';'); var_dump($node); $node->parentNode->replaceChild($span, $node); } } var_dump($dom->saveHTML());
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 17, Position 2 = 45
Branch analysis from position: 17
Jump found. Position 1 = 18, Position 2 = 45
Branch analysis from position: 18
Jump found. Position 1 = 26, Position 2 = 44
Branch analysis from position: 26
Jump found. Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 44
Branch analysis from position: 45
Jump found. Position 1 = -2
Branch analysis from position: 45
filename:       /in/OKBHo
function name:  (null)
number of ops:  52
compiled vars:  !0 = $html, !1 = $dom, !2 = $xpath, !3 = $nodes, !4 = $node, !5 = $color, !6 = $span, !7 = $document
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   3     0  E >   NOP                                                      
  11     1        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'
  13     2        NEW                                              $9      :-5
         3        DO_FCALL                                      0          
         4        ASSIGN                                                   !1, $9
  14     5        INIT_METHOD_CALL                                         !1, 'loadHTML'
         6        SEND_VAR_EX                                              !0
         7        DO_FCALL                                      0          
  16     8        NEW                                              $13     :-1
         9        SEND_VAR_EX                                              !1
        10        DO_FCALL                                      0          
        11        ASSIGN                                                   !2, $13
  18    12        INIT_METHOD_CALL                                         !2, 'evaluate'
        13        SEND_VAL_EX                                              '%2Fhtml%2Fbody%2F%2Ftext%28%29'
        14        DO_FCALL                                      0  $16     
        15        ASSIGN                                                   !3, $16
  20    16      > FE_RESET_R                                       $18     !3, ->45
        17    > > FE_FETCH_R                                               $18, !4, ->45
  21    18    >   INIT_FCALL                                               'getcolor'
        19        SEND_VAR                                                 !4
        20        DO_FCALL                                      0  $19     
        21        ASSIGN                                                   !5, $19
  22    22        INIT_FCALL                                               'var_dump'
        23        SEND_VAR                                                 !5
        24        DO_ICALL                                                 
  23    25      > JMPZ                                                     !5, ->44
  24    26    >   INIT_METHOD_CALL                                         !7, 'createElement'
        27        SEND_VAL_EX                                              'span'
        28        DO_FCALL                                      0  $22     
        29        ASSIGN                                                   !6, $22
  25    30        INIT_METHOD_CALL                                         !6, 'setAttribute'
        31        SEND_VAL_EX                                              'style'
        32        CONCAT                                           ~24     'color%3A+', !5
        33        CONCAT                                           ~25     ~24, '%3B'
        34        SEND_VAL_EX                                              ~25
        35        DO_FCALL                                      0          
  27    36        INIT_FCALL                                               'var_dump'
        37        SEND_VAR                                                 !4
        38        DO_ICALL                                                 
  29    39        FETCH_OBJ_R                                      $28     !4, 'parentNode'
        40        INIT_METHOD_CALL                                         $28, 'replaceChild'
        41        SEND_VAR_EX                                              !6
        42        SEND_VAR_EX                                              !4
        43        DO_FCALL                                      0          
        44    > > JMP                                                      ->17
        45    >   FE_FREE                                                  $18
  33    46        INIT_FCALL                                               'var_dump'
        47        INIT_METHOD_CALL                                         !1, 'saveHTML'
        48        DO_FCALL                                      0  $30     
        49        SEND_VAR                                                 $30
        50        DO_ICALL                                                 
        51      > RETURN                                                   1

Function getcolor:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 12
Branch analysis from position: 12
Jump found. Position 1 = 14, Position 2 = 2
Branch analysis from position: 14
Jump found. Position 1 = -2
Branch analysis from position: 2
Jump found. Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
Jump found. Position 1 = -2
Branch analysis from position: 12
filename:       /in/OKBHo
function name:  getColor
number of ops:  15
compiled vars:  !0 = $domnode
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   3     0  E >   RECV                                             !0      
   4     1      > JMP                                                      ->12
   5     2    >   FETCH_OBJ_R                                      $1      !0, 'parentNode'
         3        INIT_METHOD_CALL                                         $1, 'getAttribute'
         4        SEND_VAL_EX                                              'color'
         5        DO_FCALL                                      0  $2      
         6      > JMPZ                                                     $2, ->12
   6     7    >   FETCH_OBJ_R                                      $3      !0, 'parentNode'
         8        INIT_METHOD_CALL                                         $3, 'getAttribute'
         9        SEND_VAL_EX                                              'color'
        10        DO_FCALL                                      0  $4      
        11      > RETURN                                                   $4
   4    12    >   FETCH_OBJ_R                                      $5      !0, 'parentNode'
        13      > JMPNZ                                                    $5, ->2
   9    14    > > RETURN                                                   null

End of function getcolor

Generated using Vulcan Logic Dumper, using php 7.2.0