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

End of function _handle_uls

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.46 ms | 1407 KiB | 16 Q