3v4l.org

run code in 300+ PHP versions simultaneously
<?php function do_it($in) { $a = new DOMDocument(); $a->loadHTML($in); $xpath = new DOMXpath($a); foreach($xpath->query('/html/body//ul') as $node) _handle_uls($node); return $a->textContent; } function _handle_uls(DOMNode $node) { echo 'Works:' . "\n\n"; foreach ($node->childNodes as $subnode) echo '* ' . trim($subnode->textContent) . "\n"; echo "\n\n\n" . 'Problems:' . "\n\n"; var_dump($node->nodeName); foreach ($node->childNodes as $subnode) { var_dump($subnode->nodeName); $textNode = $subnode->ownerDocument->createTextNode('* ' . trim($subnode->textContent) . "\n"); $subnode->ownerDocument->importNode($textNode); $subnode->parentNode->replaceChild($textNode, $subnode); } } $HTML = '<ul><li>Potatoes</li><li>Tomatoes</li><li>Carrots</li></ul>'; echo do_it($HTML);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gHEZe
function name:  (null)
number of ops:  6
compiled vars:  !0 = $HTML
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   ASSIGN                                                   !0, '%3Cul%3E%3Cli%3EPotatoes%3C%2Fli%3E%3Cli%3ETomatoes%3C%2Fli%3E%3Cli%3ECarrots%3C%2Fli%3E%3C%2Ful%3E'
   39     1        INIT_FCALL                                               'do_it'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $2      
          4        ECHO                                                     $2
          5      > RETURN                                                   1

Function do_it:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 20
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 20
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/gHEZe
function name:  do_it
number of ops:  24
compiled vars:  !0 = $in, !1 = $a, !2 = $xpath, !3 = $node
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        NEW                                              $4      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $4
    6     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
    7     7        NEW                                              $8      'DOMXpath'
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !2, $8
    9    11        INIT_METHOD_CALL                                         !2, 'query'
         12        SEND_VAL_EX                                              '%2Fhtml%2Fbody%2F%2Ful'
         13        DO_FCALL                                      0  $11     
         14      > FE_RESET_R                                       $12     $11, ->20
         15    > > FE_FETCH_R                                               $12, !3, ->20
   10    16    >   INIT_FCALL_BY_NAME                                       '_handle_uls'
         17        SEND_VAR_EX                                              !3
         18        DO_FCALL                                      0          
    9    19      > JMP                                                      ->15
         20    >   FE_FREE                                                  $12
   12    21        FETCH_OBJ_R                                      ~14     !1, 'textContent'
         22      > RETURN                                                   ~14
   13    23*     > RETURN                                                   null

End of function do_it

Function _handle_uls:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 13
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 13
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 47
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 47
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
Branch analysis from position: 13
filename:       /in/gHEZe
function name:  _handle_uls
number of ops:  49
compiled vars:  !0 = $node, !1 = $subnode, !2 = $textNode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   17     1        ECHO                                                     'Works%3A%0A%0A'
   19     2        FETCH_OBJ_R                                      ~3      !0, 'childNodes'
          3      > FE_RESET_R                                       $4      ~3, ->13
          4    > > FE_FETCH_R                                               $4, !1, ->13
   20     5    >   INIT_FCALL                                               'trim'
          6        FETCH_OBJ_R                                      ~5      !1, 'textContent'
          7        SEND_VAL                                                 ~5
          8        DO_ICALL                                         $6      
          9        CONCAT                                           ~7      '%2A+', $6
         10        CONCAT                                           ~8      ~7, '%0A'
         11        ECHO                                                     ~8
   19    12      > JMP                                                      ->4
         13    >   FE_FREE                                                  $4
   22    14        ECHO                                                     '%0A%0A%0AProblems%3A%0A%0A'
   24    15        INIT_FCALL                                               'var_dump'
         16        FETCH_OBJ_R                                      ~9      !0, 'nodeName'
         17        SEND_VAL                                                 ~9
         18        DO_ICALL                                                 
   26    19        FETCH_OBJ_R                                      ~11     !0, 'childNodes'
         20      > FE_RESET_R                                       $12     ~11, ->47
         21    > > FE_FETCH_R                                               $12, !1, ->47
   29    22    >   INIT_FCALL                                               'var_dump'
         23        FETCH_OBJ_R                                      ~13     !1, 'nodeName'
         24        SEND_VAL                                                 ~13
         25        DO_ICALL                                                 
   31    26        FETCH_OBJ_R                                      ~15     !1, 'ownerDocument'
         27        INIT_METHOD_CALL                                         ~15, 'createTextNode'
         28        INIT_FCALL                                               'trim'
         29        FETCH_OBJ_R                                      ~16     !1, 'textContent'
         30        SEND_VAL                                                 ~16
         31        DO_ICALL                                         $17     
         32        CONCAT                                           ~18     '%2A+', $17
         33        CONCAT                                           ~19     ~18, '%0A'
         34        SEND_VAL_EX                                              ~19
         35        DO_FCALL                                      0  $20     
         36        ASSIGN                                                   !2, $20
   32    37        FETCH_OBJ_R                                      ~22     !1, 'ownerDocument'
         38        INIT_METHOD_CALL                                         ~22, 'importNode'
         39        SEND_VAR_EX                                              !2
         40        DO_FCALL                                      0          
   33    41        FETCH_OBJ_R                                      ~24     !1, 'parentNode'
         42        INIT_METHOD_CALL                                         ~24, 'replaceChild'
         43        SEND_VAR_EX                                              !2
         44        SEND_VAR_EX                                              !1
         45        DO_FCALL                                      0          
   26    46      > JMP                                                      ->21
         47    >   FE_FREE                                                  $12
   35    48      > RETURN                                                   null

End of function _handle_uls

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.57 ms | 1407 KiB | 18 Q