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

End of function _handle_uls

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.89 ms | 1403 KiB | 18 Q