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"; foreach (iterator_to_array($node->childNodes) as $subnode) { $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/evvlG
function name:  (null)
number of ops:  6
compiled vars:  !0 = $HTML
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   ASSIGN                                                   !0, '%3Cul%3E%3Cli%3EPotatoes%3C%2Fli%3E%3Cli%3ETomatoes%3C%2Fli%3E%3Cli%3ECarrots%3C%2Fli%3E%3C%2Ful%3E'
   33     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/evvlG
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 = 42
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 42
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
Branch analysis from position: 13
filename:       /in/evvlG
function name:  _handle_uls
number of ops:  44
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                                               'iterator_to_array'
         16        FETCH_OBJ_R                                      ~9      !0, 'childNodes'
         17        SEND_VAL                                                 ~9
         18        DO_ICALL                                         $10     
         19      > FE_RESET_R                                       $11     $10, ->42
         20    > > FE_FETCH_R                                               $11, !1, ->42
   25    21    >   FETCH_OBJ_R                                      ~12     !1, 'ownerDocument'
         22        INIT_METHOD_CALL                                         ~12, 'createTextNode'
         23        INIT_FCALL                                               'trim'
         24        FETCH_OBJ_R                                      ~13     !1, 'textContent'
         25        SEND_VAL                                                 ~13
         26        DO_ICALL                                         $14     
         27        CONCAT                                           ~15     '%2A+', $14
         28        CONCAT                                           ~16     ~15, '%0A'
         29        SEND_VAL_EX                                              ~16
         30        DO_FCALL                                      0  $17     
         31        ASSIGN                                                   !2, $17
   26    32        FETCH_OBJ_R                                      ~19     !1, 'ownerDocument'
         33        INIT_METHOD_CALL                                         ~19, 'importNode'
         34        SEND_VAR_EX                                              !2
         35        DO_FCALL                                      0          
   27    36        FETCH_OBJ_R                                      ~21     !1, 'parentNode'
         37        INIT_METHOD_CALL                                         ~21, 'replaceChild'
         38        SEND_VAR_EX                                              !2
         39        SEND_VAR_EX                                              !1
         40        DO_FCALL                                      0          
   24    41      > JMP                                                      ->20
         42    >   FE_FREE                                                  $11
   29    43      > RETURN                                                   null

End of function _handle_uls

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.68 ms | 1411 KiB | 18 Q