3v4l.org

run code in 300+ PHP versions simultaneously
<?php $doc = new DOMDocument(); $doc->loadHTML('<html><body><a href="teste.php">Teste</a><a href="../teste2.php">Teste2</a></body></html>'); $links = $doc->getElementsByTagName('a'); print_r($links); foreach($links as $link) { echo $link->getAttribute('href') . "\n"; } echo $doc->saveHTML() . "\n\n"; $body = $doc->getElementsByTagName('body')[0]; $select = $doc->createElement('select'); $body->appendChild($select); echo $doc->saveHTML() . "\n\n"; function addElement($doc, $newElement, $parentElement, $attributesArray = null) { $pe = $doc->getElementsByTagName($parentElement)[0]; $ne = $doc->createElement($newElement); $pe->appendChild($ne); if (isset($attributesArray)) { while ( ($current = current($attributesArray)) ) { print_r($current); $attrib = key($current); $domAttribute = $doc->createAttribute($attrib); // Value for the created attribute $domAttribute->value = $current[$attrib]; // Don't forget to append it to the element $ne->appendChild($domAttribute); echo $attrib . '=' . $current[$attrib] . "\n"; next($array); } } echo $doc->saveHTML(); } $attribs = [ ['style' => '"border:1px solid black;"'] ]; addElement($doc, 'ul', 'select', $attribs);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 21
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 21
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/2LSkY
function name:  (null)
number of ops:  50
compiled vars:  !0 = $doc, !1 = $links, !2 = $link, !3 = $body, !4 = $select, !5 = $attribs
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   NEW                                              $6      'DOMDocument'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $6
    5     3        INIT_METHOD_CALL                                         !0, 'loadHTML'
          4        SEND_VAL_EX                                              '%3Chtml%3E%3Cbody%3E%3Ca+href%3D%22teste.php%22%3ETeste%3C%2Fa%3E%3Ca+href%3D%22..%2Fteste2.php%22%3ETeste2%3C%2Fa%3E%3C%2Fbody%3E%3C%2Fhtml%3E'
          5        DO_FCALL                                      0          
    7     6        INIT_METHOD_CALL                                         !0, 'getElementsByTagName'
          7        SEND_VAL_EX                                              'a'
          8        DO_FCALL                                      0  $10     
          9        ASSIGN                                                   !1, $10
    9    10        INIT_FCALL                                               'print_r'
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                                 
   11    13      > FE_RESET_R                                       $13     !1, ->21
         14    > > FE_FETCH_R                                               $13, !2, ->21
   12    15    >   INIT_METHOD_CALL                                         !2, 'getAttribute'
         16        SEND_VAL_EX                                              'href'
         17        DO_FCALL                                      0  $14     
         18        CONCAT                                           ~15     $14, '%0A'
         19        ECHO                                                     ~15
   11    20      > JMP                                                      ->14
         21    >   FE_FREE                                                  $13
   15    22        INIT_METHOD_CALL                                         !0, 'saveHTML'
         23        DO_FCALL                                      0  $16     
         24        CONCAT                                           ~17     $16, '%0A%0A'
         25        ECHO                                                     ~17
   17    26        INIT_METHOD_CALL                                         !0, 'getElementsByTagName'
         27        SEND_VAL_EX                                              'body'
         28        DO_FCALL                                      0  $18     
         29        FETCH_DIM_R                                      ~19     $18, 0
         30        ASSIGN                                                   !3, ~19
   18    31        INIT_METHOD_CALL                                         !0, 'createElement'
         32        SEND_VAL_EX                                              'select'
         33        DO_FCALL                                      0  $21     
         34        ASSIGN                                                   !4, $21
   19    35        INIT_METHOD_CALL                                         !3, 'appendChild'
         36        SEND_VAR_EX                                              !4
         37        DO_FCALL                                      0          
   21    38        INIT_METHOD_CALL                                         !0, 'saveHTML'
         39        DO_FCALL                                      0  $24     
         40        CONCAT                                           ~25     $24, '%0A%0A'
         41        ECHO                                                     ~25
   46    42        ASSIGN                                                   !5, <array>
   49    43        INIT_FCALL                                               'addelement'
         44        SEND_VAR                                                 !0
         45        SEND_VAL                                                 'ul'
         46        SEND_VAL                                                 'select'
         47        SEND_VAR                                                 !5
         48        DO_FCALL                                      0          
         49      > RETURN                                                   1

Function addelement:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 49
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 19
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 19
Branch analysis from position: 49
Branch analysis from position: 19
Branch analysis from position: 49
filename:       /in/2LSkY
function name:  addElement
number of ops:  53
compiled vars:  !0 = $doc, !1 = $newElement, !2 = $parentElement, !3 = $attributesArray, !4 = $pe, !5 = $ne, !6 = $current, !7 = $attrib, !8 = $domAttribute, !9 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV_INIT                                        !3      null
   25     4        INIT_METHOD_CALL                                         !0, 'getElementsByTagName'
          5        SEND_VAR_EX                                              !2
          6        DO_FCALL                                      0  $10     
          7        FETCH_DIM_R                                      ~11     $10, 0
          8        ASSIGN                                                   !4, ~11
   26     9        INIT_METHOD_CALL                                         !0, 'createElement'
         10        SEND_VAR_EX                                              !1
         11        DO_FCALL                                      0  $13     
         12        ASSIGN                                                   !5, $13
   27    13        INIT_METHOD_CALL                                         !4, 'appendChild'
         14        SEND_VAR_EX                                              !5
         15        DO_FCALL                                      0          
   29    16        ISSET_ISEMPTY_CV                                         !3
         17      > JMPZ                                                     ~16, ->49
   30    18    > > JMP                                                      ->44
   31    19    >   INIT_FCALL                                               'print_r'
         20        SEND_VAR                                                 !6
         21        DO_ICALL                                                 
   32    22        INIT_FCALL                                               'key'
         23        SEND_VAR                                                 !6
         24        DO_ICALL                                         $18     
         25        ASSIGN                                                   !7, $18
   33    26        INIT_METHOD_CALL                                         !0, 'createAttribute'
         27        SEND_VAR_EX                                              !7
         28        DO_FCALL                                      0  $20     
         29        ASSIGN                                                   !8, $20
   35    30        FETCH_DIM_R                                      ~23     !6, !7
         31        ASSIGN_OBJ                                               !8, 'value'
         32        OP_DATA                                                  ~23
   37    33        INIT_METHOD_CALL                                         !5, 'appendChild'
         34        SEND_VAR_EX                                              !8
         35        DO_FCALL                                      0          
   38    36        CONCAT                                           ~25     !7, '%3D'
         37        FETCH_DIM_R                                      ~26     !6, !7
         38        CONCAT                                           ~27     ~25, ~26
         39        CONCAT                                           ~28     ~27, '%0A'
         40        ECHO                                                     ~28
   39    41        INIT_FCALL                                               'next'
         42        SEND_REF                                                 !9
         43        DO_ICALL                                                 
   30    44    >   INIT_FCALL                                               'current'
         45        SEND_VAR                                                 !3
         46        DO_ICALL                                         $30     
         47        ASSIGN                                           ~31     !6, $30
         48      > JMPNZ                                                    ~31, ->19
   43    49    >   INIT_METHOD_CALL                                         !0, 'saveHTML'
         50        DO_FCALL                                      0  $32     
         51        ECHO                                                     $32
   44    52      > RETURN                                                   null

End of function addelement

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
183.08 ms | 1398 KiB | 22 Q