3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xml = <<<'XML' <?xml version="1.0"?> <books> <book> <isbn>123456789098</isbn> <title>Harry Potter</title> <author>J K. Rowling</author> <edition>2005</edition> </book> <book> <placeItHere></placeItHere> <isbn>1</isbn> <title>stuffs</title> <author>DA</author> <edition>2014</edition> </book> </books> XML; $book = [ 'isbn' => 123456789099, 'title' => 'Harry & Potter 3', 'author' => 'J K. Rowling', 'edition' => '2007' ]; $dom = new DOMDocument(); $dom->formatOutput = true; $dom->preserveWhiteSpace = false; $dom->loadXML($xml); $xpath = new DOMXPath($dom); $placeItHere = $xpath->query('/books/book/placeItHere')->item(0); $newBook = $placeItHere->appendChild($dom->createElement('book')); foreach ($book as $part => $value) { $element = $newBook->appendChild($dom->createElement($part, $value)); } echo $dom->saveXML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 31, Position 2 = 42
Branch analysis from position: 31
2 jumps found. (Code = 78) Position 1 = 32, Position 2 = 42
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
filename:       /in/cSeiv
function name:  (null)
number of ops:  47
compiled vars:  !0 = $xml, !1 = $book, !2 = $dom, !3 = $xpath, !4 = $placeItHere, !5 = $newBook, !6 = $value, !7 = $part, !8 = $element
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3C%3Fxml+version%3D%221.0%22%3F%3E%0A%3Cbooks%3E%0A++++%3Cbook%3E%0A++++++++%3Cisbn%3E123456789098%3C%2Fisbn%3E%0A++++++++%3Ctitle%3EHarry+Potter%3C%2Ftitle%3E%0A++++++++%3Cauthor%3EJ+K.+Rowling%3C%2Fauthor%3E%0A++++++++%3Cedition%3E2005%3C%2Fedition%3E%0A++++%3C%2Fbook%3E%0A++++%3Cbook%3E%0A++++++++%3CplaceItHere%3E%3C%2FplaceItHere%3E%0A++++++++%3Cisbn%3E1%3C%2Fisbn%3E%0A++++++++%3Ctitle%3Estuffs%3C%2Ftitle%3E%0A++++++++%3Cauthor%3EDA%3C%2Fauthor%3E%0A++++++++%3Cedition%3E2014%3C%2Fedition%3E%0A++++%3C%2Fbook%3E%0A%3C%2Fbooks%3E'
   22     1        ASSIGN                                                   !1, <array>
   29     2        NEW                                              $11     'DOMDocument'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !2, $11
   30     5        ASSIGN_OBJ                                               !2, 'formatOutput'
          6        OP_DATA                                                  <true>
   31     7        ASSIGN_OBJ                                               !2, 'preserveWhiteSpace'
          8        OP_DATA                                                  <false>
   32     9        INIT_METHOD_CALL                                         !2, 'loadXML'
         10        SEND_VAR_EX                                              !0
         11        DO_FCALL                                      0          
   33    12        NEW                                              $17     'DOMXPath'
         13        SEND_VAR_EX                                              !2
         14        DO_FCALL                                      0          
         15        ASSIGN                                                   !3, $17
   35    16        INIT_METHOD_CALL                                         !3, 'query'
         17        SEND_VAL_EX                                              '%2Fbooks%2Fbook%2FplaceItHere'
         18        DO_FCALL                                      0  $20     
         19        INIT_METHOD_CALL                                         $20, 'item'
         20        SEND_VAL_EX                                              0
         21        DO_FCALL                                      0  $21     
         22        ASSIGN                                                   !4, $21
   36    23        INIT_METHOD_CALL                                         !4, 'appendChild'
         24        INIT_METHOD_CALL                                         !2, 'createElement'
         25        SEND_VAL_EX                                              'book'
         26        DO_FCALL                                      0  $23     
         27        SEND_VAR_NO_REF_EX                                       $23
         28        DO_FCALL                                      0  $24     
         29        ASSIGN                                                   !5, $24
   37    30      > FE_RESET_R                                       $26     !1, ->42
         31    > > FE_FETCH_R                                       ~27     $26, !6, ->42
         32    >   ASSIGN                                                   !7, ~27
   38    33        INIT_METHOD_CALL                                         !5, 'appendChild'
         34        INIT_METHOD_CALL                                         !2, 'createElement'
         35        SEND_VAR_EX                                              !7
         36        SEND_VAR_EX                                              !6
         37        DO_FCALL                                      0  $29     
         38        SEND_VAR_NO_REF_EX                                       $29
         39        DO_FCALL                                      0  $30     
         40        ASSIGN                                                   !8, $30
   37    41      > JMP                                                      ->31
         42    >   FE_FREE                                                  $26
   41    43        INIT_METHOD_CALL                                         !2, 'saveXML'
         44        DO_FCALL                                      0  $32     
         45        ECHO                                                     $32
         46      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.99 ms | 1399 KiB | 13 Q