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); 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/NjsSn
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/NjsSn
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 = 20, Position 2 = 46
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 46
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
Branch analysis from position: 13
filename:       /in/NjsSn
function name:  _handle_uls
number of ops:  48
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        SEND_VAR                                                 !0
         17        DO_ICALL                                                 
   26    18        FETCH_OBJ_R                                      ~10     !0, 'childNodes'
         19      > FE_RESET_R                                       $11     ~10, ->46
         20    > > FE_FETCH_R                                               $11, !1, ->46
   29    21    >   INIT_FCALL                                               'var_dump'
         22        FETCH_OBJ_R                                      ~12     !1, 'nodeName'
         23        SEND_VAL                                                 ~12
         24        DO_ICALL                                                 
   31    25        FETCH_OBJ_R                                      ~14     !1, 'ownerDocument'
         26        INIT_METHOD_CALL                                         ~14, 'createTextNode'
         27        INIT_FCALL                                               'trim'
         28        FETCH_OBJ_R                                      ~15     !1, 'textContent'
         29        SEND_VAL                                                 ~15
         30        DO_ICALL                                         $16     
         31        CONCAT                                           ~17     '%2A+', $16
         32        CONCAT                                           ~18     ~17, '%0A'
         33        SEND_VAL_EX                                              ~18
         34        DO_FCALL                                      0  $19     
         35        ASSIGN                                                   !2, $19
   32    36        FETCH_OBJ_R                                      ~21     !1, 'ownerDocument'
         37        INIT_METHOD_CALL                                         ~21, 'importNode'
         38        SEND_VAR_EX                                              !2
         39        DO_FCALL                                      0          
   33    40        FETCH_OBJ_R                                      ~23     !1, 'parentNode'
         41        INIT_METHOD_CALL                                         ~23, 'replaceChild'
         42        SEND_VAR_EX                                              !2
         43        SEND_VAR_EX                                              !1
         44        DO_FCALL                                      0          
   26    45      > JMP                                                      ->20
         46    >   FE_FREE                                                  $11
   35    47      > RETURN                                                   null

End of function _handle_uls

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.3 ms | 1411 KiB | 18 Q