3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = <<<'AHA' <section debug = 'mysection'> <div> <div id = 'current' debug ='container'> <p id = 'last' debug = 'message'> </p> </div> </div> </section> AHA; $doc = new DOMDocument(); libxml_use_internal_errors(true); $doc->loadHTML($str); libxml_clear_errors(); $node = $doc->getElementById('last'); function getDebugNodes($node) { while($node = $node->parentNode){ if($node->nodeType===1 AND$node->hasAttribute('debug')){ $snake[] = $node; } } return $snake; } //echo "\n" . $node->getAttribute('name') . $node->getAttribute('debug'); function make($snake, $index) { $path = ''; for($i = $index; $i < count($snake) - $index; $i++) { $path = "{$snake[$i]->getAttribute('debug')} $path"; } return $path; } $snake = getDebugNodes($node); array_unshift($snake, $node); //foreach($snake as $element){ // echo ' ' . $element->getAttribute('debug'); //} echo "\n" . make($snake, 0);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tAUn5
function name:  (null)
number of ops:  31
compiled vars:  !0 = $str, !1 = $doc, !2 = $node, !3 = $snake
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%3Csection+debug+%3D+%27mysection%27%3E%0A%3Cdiv%3E%0A%3Cdiv+id+%3D+%27current%27+debug++%3D%27container%27%3E%0A%3Cp+id+%3D+%27last%27+debug+%3D+%27message%27%3E%0A%3C%2Fp%3E%0A%3C%2Fdiv%3E%0A%3C%2Fdiv%3E%0A%3C%2Fsection%3E'
   12     1        NEW                                              $5      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $5
   13     4        INIT_FCALL                                               'libxml_use_internal_errors'
          5        SEND_VAL                                                 <true>
          6        DO_ICALL                                                 
   14     7        INIT_METHOD_CALL                                         !1, 'loadHTML'
          8        SEND_VAR_EX                                              !0
          9        DO_FCALL                                      0          
   15    10        INIT_FCALL                                               'libxml_clear_errors'
         11        DO_ICALL                                                 
   16    12        INIT_METHOD_CALL                                         !1, 'getElementById'
         13        SEND_VAL_EX                                              'last'
         14        DO_FCALL                                      0  $11     
         15        ASSIGN                                                   !2, $11
   35    16        INIT_FCALL                                               'getdebugnodes'
         17        SEND_VAR                                                 !2
         18        DO_FCALL                                      0  $13     
         19        ASSIGN                                                   !3, $13
   36    20        INIT_FCALL                                               'array_unshift'
         21        SEND_REF                                                 !3
         22        SEND_VAR                                                 !2
         23        DO_ICALL                                                 
   42    24        INIT_FCALL                                               'make'
         25        SEND_VAR                                                 !3
         26        SEND_VAL                                                 0
         27        DO_FCALL                                      0  $16     
         28        CONCAT                                           ~17     '%0A', $16
         29        ECHO                                                     ~17
         30      > RETURN                                                   1

Function getdebugnodes:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 2
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 2
2 jumps found. (Code = 46) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 2
Branch analysis from position: 15
Branch analysis from position: 2
Branch analysis from position: 12
Branch analysis from position: 9
filename:       /in/tAUn5
function name:  getDebugNodes
number of ops:  17
compiled vars:  !0 = $node, !1 = $snake
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   18     1      > JMP                                                      ->12
   19     2    >   FETCH_OBJ_R                                      ~2      !0, 'nodeType'
          3        IS_IDENTICAL                                     ~3      ~2, 1
          4      > JMPZ_EX                                          ~3      ~3, ->9
          5    >   INIT_METHOD_CALL                                         !0, 'hasAttribute'
          6        SEND_VAL_EX                                              'debug'
          7        DO_FCALL                                      0  $4      
          8        BOOL                                             ~3      $4
          9    > > JMPZ                                                     ~3, ->12
   20    10    >   ASSIGN_DIM                                               !1
         11        OP_DATA                                                  !0
   18    12    >   FETCH_OBJ_R                                      ~6      !0, 'parentNode'
         13        ASSIGN                                           ~7      !0, ~6
         14      > JMPNZ                                                    ~7, ->2
   23    15    > > RETURN                                                   !1
   24    16*     > RETURN                                                   null

End of function getdebugnodes

Function make:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 5
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 5
Branch analysis from position: 18
Branch analysis from position: 5
filename:       /in/tAUn5
function name:  make
number of ops:  20
compiled vars:  !0 = $snake, !1 = $index, !2 = $path, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   29     2        ASSIGN                                                   !2, ''
   30     3        ASSIGN                                                   !3, !1
          4      > JMP                                                      ->14
   31     5    >   FETCH_DIM_R                                      ~6      !0, !3
          6        INIT_METHOD_CALL                                         ~6, 'getAttribute'
          7        SEND_VAL_EX                                              'debug'
          8        DO_FCALL                                      0  $7      
          9        ROPE_INIT                                     3  ~9      $7
         10        ROPE_ADD                                      1  ~9      ~9, '+'
         11        ROPE_END                                      2  ~8      ~9, !2
         12        ASSIGN                                                   !2, ~8
   30    13        PRE_INC                                                  !3
         14    >   COUNT                                            ~13     !0
         15        SUB                                              ~14     ~13, !1
         16        IS_SMALLER                                               !3, ~14
         17      > JMPNZ                                                    ~15, ->5
   33    18    > > RETURN                                                   !2
   34    19*     > RETURN                                                   null

End of function make

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.88 ms | 1406 KiB | 22 Q