3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = <<<'XML' <a> <b> <c>text</c> <c>stuff</c> </b> <d> <c>code</c> </d> </a> XML; // load source XML and create Xpath instance $source = new DOMDocument(); $source->loadxml($string); $xpath = new DOMXpath($source); // create target document with document element $target = new DOMDocument(); $root = $target->appendChild($dom->createElement('d')); // copy nodes from source to target foreach ($xpath->evaluate('/a/b/c') as $child) { $root->appendChild($target->importNode($child)); } // output target echo $target->saveXml();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 33
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 33
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/oXNHK
function name:  (null)
number of ops:  38
compiled vars:  !0 = $string, !1 = $source, !2 = $xpath, !3 = $target, !4 = $root, !5 = $dom, !6 = $child
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Ca%3E+%3Cb%3E+%3Cc%3Etext%3C%2Fc%3E+%3Cc%3Estuff%3C%2Fc%3E+%3C%2Fb%3E+%3Cd%3E+%3Cc%3Ecode%3C%2Fc%3E+%3C%2Fd%3E+%3C%2Fa%3E'
    8     1        NEW                                              $8      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $8
    9     4        INIT_METHOD_CALL                                         !1, 'loadxml'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   10     7        NEW                                              $12     'DOMXpath'
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !2, $12
   13    11        NEW                                              $15     'DOMDocument'
         12        DO_FCALL                                      0          
         13        ASSIGN                                                   !3, $15
   14    14        INIT_METHOD_CALL                                         !3, 'appendChild'
         15        INIT_METHOD_CALL                                         !5, 'createElement'
         16        SEND_VAL_EX                                              'd'
         17        DO_FCALL                                      0  $18     
         18        SEND_VAR_NO_REF_EX                                       $18
         19        DO_FCALL                                      0  $19     
         20        ASSIGN                                                   !4, $19
   17    21        INIT_METHOD_CALL                                         !2, 'evaluate'
         22        SEND_VAL_EX                                              '%2Fa%2Fb%2Fc'
         23        DO_FCALL                                      0  $21     
         24      > FE_RESET_R                                       $22     $21, ->33
         25    > > FE_FETCH_R                                               $22, !6, ->33
   18    26    >   INIT_METHOD_CALL                                         !4, 'appendChild'
         27        INIT_METHOD_CALL                                         !3, 'importNode'
         28        SEND_VAR_EX                                              !6
         29        DO_FCALL                                      0  $23     
         30        SEND_VAR_NO_REF_EX                                       $23
         31        DO_FCALL                                      0          
   17    32      > JMP                                                      ->25
         33    >   FE_FREE                                                  $22
   22    34        INIT_METHOD_CALL                                         !3, 'saveXml'
         35        DO_FCALL                                      0  $25     
         36        ECHO                                                     $25
         37      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.3 ms | 1395 KiB | 13 Q