3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xmlString = <<<XML <root> <teams> <team>Silverbacks</team> <team>Golden Eyes</team> </teams> </root> XML; $domDoc = new DOMDocument(); $domDoc->loadXML($xmlString); $textElement = $domDoc->createElement('team', 'Bearhides'); $result = $domDoc->xpath('teams/team[2]'); $result[1]->insertBefore($textElement); echo $domDoc->saveXML."\n\n"; //print_r($domDoc->saveXML() ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9phLN
function name:  (null)
number of ops:  24
compiled vars:  !0 = $xmlString, !1 = $domDoc, !2 = $textElement, !3 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Croot%3E%0A%3Cteams%3E%0A%3Cteam%3ESilverbacks%3C%2Fteam%3E%0A%3Cteam%3EGolden+Eyes%3C%2Fteam%3E%0A%3C%2Fteams%3E%0A%3C%2Froot%3E'
   11     1        NEW                                              $5      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $5
   12     4        INIT_METHOD_CALL                                         !1, 'loadXML'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   13     7        INIT_METHOD_CALL                                         !1, 'createElement'
          8        SEND_VAL_EX                                              'team'
          9        SEND_VAL_EX                                              'Bearhides'
         10        DO_FCALL                                      0  $9      
         11        ASSIGN                                                   !2, $9
   14    12        INIT_METHOD_CALL                                         !1, 'xpath'
         13        SEND_VAL_EX                                              'teams%2Fteam%5B2%5D'
         14        DO_FCALL                                      0  $11     
         15        ASSIGN                                                   !3, $11
   15    16        FETCH_DIM_R                                      ~13     !3, 1
         17        INIT_METHOD_CALL                                         ~13, 'insertBefore'
         18        SEND_VAR_EX                                              !2
         19        DO_FCALL                                      0          
   18    20        FETCH_OBJ_R                                      ~15     !1, 'saveXML'
         21        CONCAT                                           ~16     ~15, '%0A%0A'
         22        ECHO                                                     ~16
   21    23      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.81 ms | 1394 KiB | 13 Q