3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xml = '<?xml version="1.0" encoding="utf-8"?> <products> <item> <reference>00001</reference> <other_string>PRODUCT 1</other_string> <brand>BRAND 1</brand> <promo>YES</promo> </item> <item> <reference>00002</reference> <other_string>PRODUCT 2</other_string> <brand>BRAND 2</brand> <promo>YES</promo> </item> <item> <reference>00003</reference> <other_string>PRODUCT 3</other_string> <brand>BRAND 3</brand> <promo>NO</promo> </item> <item> <reference>00004</reference> <other_string>PRODUCT 4</other_string> <brand>BRAND 4</brand> <promo>NO</promo> </item> <item> <reference>00005</reference> <other_string>PRODUCT 5</other_string> <brand>BRAND 5</brand> <promo>YES</promo> </item> </products>'; $doc = new DOMDocument(); $doc->loadXML($xml); foreach ($doc->getElementsByTagName('promo') as $ele) { $newnode = $doc->createElement('newnode'); $newnode->nodeValue = $ele->nodeValue == 'YES' ? 1 : 0; $ele->parentNode->appendChild($newnode); } echo $doc->saveXML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 29
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 29
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
filename:       /in/asVci
function name:  (null)
number of ops:  34
compiled vars:  !0 = $xml, !1 = $doc, !2 = $ele, !3 = $newnode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%3C%3Fxml+version%3D%221.0%22+encoding%3D%22utf-8%22%3F%3E%0A%3Cproducts%3E%0A++%3Citem%3E%0A++++%3Creference%3E00001%3C%2Freference%3E%0A++++%3Cother_string%3EPRODUCT+1%3C%2Fother_string%3E%0A++++%3Cbrand%3EBRAND+1%3C%2Fbrand%3E%0A++++%3Cpromo%3EYES%3C%2Fpromo%3E%0A++%3C%2Fitem%3E%0A++%3Citem%3E%0A++++%3Creference%3E00002%3C%2Freference%3E%0A++++%3Cother_string%3EPRODUCT+2%3C%2Fother_string%3E%0A++++%3Cbrand%3EBRAND+2%3C%2Fbrand%3E%0A++++%3Cpromo%3EYES%3C%2Fpromo%3E%0A++%3C%2Fitem%3E%0A++%3Citem%3E%0A++++%3Creference%3E00003%3C%2Freference%3E%0A++++%3Cother_string%3EPRODUCT+3%3C%2Fother_string%3E%0A++++%3Cbrand%3EBRAND+3%3C%2Fbrand%3E%0A++++%3Cpromo%3ENO%3C%2Fpromo%3E%0A++%3C%2Fitem%3E%0A++%3Citem%3E%0A++++%3Creference%3E00004%3C%2Freference%3E%0A++++%3Cother_string%3EPRODUCT+4%3C%2Fother_string%3E%0A++++%3Cbrand%3EBRAND+4%3C%2Fbrand%3E%0A++++%3Cpromo%3ENO%3C%2Fpromo%3E%0A++%3C%2Fitem%3E%0A++%3Citem%3E%0A++++%3Creference%3E00005%3C%2Freference%3E%0A++++%3Cother_string%3EPRODUCT+5%3C%2Fother_string%3E%0A++++%3Cbrand%3EBRAND+5%3C%2Fbrand%3E%0A++++%3Cpromo%3EYES%3C%2Fpromo%3E%0A++%3C%2Fitem%3E%0A%3C%2Fproducts%3E'
   35     1        NEW                                              $5      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $5
   36     4        INIT_METHOD_CALL                                         !1, 'loadXML'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   37     7        INIT_METHOD_CALL                                         !1, 'getElementsByTagName'
          8        SEND_VAL_EX                                              'promo'
          9        DO_FCALL                                      0  $9      
         10      > FE_RESET_R                                       $10     $9, ->29
         11    > > FE_FETCH_R                                               $10, !2, ->29
   38    12    >   INIT_METHOD_CALL                                         !1, 'createElement'
         13        SEND_VAL_EX                                              'newnode'
         14        DO_FCALL                                      0  $11     
         15        ASSIGN                                                   !3, $11
   39    16        FETCH_OBJ_R                                      ~14     !2, 'nodeValue'
         17        IS_EQUAL                                                 ~14, 'YES'
         18      > JMPZ                                                     ~15, ->21
         19    >   QM_ASSIGN                                        ~16     1
         20      > JMP                                                      ->22
         21    >   QM_ASSIGN                                        ~16     0
         22    >   ASSIGN_OBJ                                               !3, 'nodeValue'
         23        OP_DATA                                                  ~16
   40    24        FETCH_OBJ_R                                      ~17     !2, 'parentNode'
         25        INIT_METHOD_CALL                                         ~17, 'appendChild'
         26        SEND_VAR_EX                                              !3
         27        DO_FCALL                                      0          
   37    28      > JMP                                                      ->11
         29    >   FE_FREE                                                  $10
   42    30        INIT_METHOD_CALL                                         !1, 'saveXML'
         31        DO_FCALL                                      0  $19     
         32        ECHO                                                     $19
         33      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.35 ms | 1007 KiB | 13 Q