3v4l.org

run code in 300+ PHP versions simultaneously
<?php function createNodesFromHTML(DOMDocument $doc,$str) { $nodes = array(); $d = new DOMDocument(); $d->loadHTML("<html>{$str}</html>"); $child = $d->documentElement->firstChild; while($child) { $nodes[] = $doc->importNode($child,true); $child = $child->nextSibling; } return $nodes; } $dom = new DOMDocument(); $icon = '<i class="fa fa-remove"></i>'; $button = $dom->createElement('a'); $button->setAttribute('href', '/offline-bcu/delete/12345'); $button->setAttribute('class', 'ml5 mr5 btn btn-sm btn-danger'); $nodes = createNodesFromHTML($dom, $icon); $button->appendChild($nodes[0]); $dom->appendChild($button); echo $dom->saveHTML();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/s0UPJ
function name:  (null)
number of ops:  33
compiled vars:  !0 = $dom, !1 = $icon, !2 = $button, !3 = $nodes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   NEW                                              $4      'DOMDocument'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $4
   17     3        ASSIGN                                                   !1, '%3Ci+class%3D%22fa+fa-remove%22%3E%3C%2Fi%3E'
   18     4        INIT_METHOD_CALL                                         !0, 'createElement'
          5        SEND_VAL_EX                                              'a'
          6        DO_FCALL                                      0  $8      
          7        ASSIGN                                                   !2, $8
   19     8        INIT_METHOD_CALL                                         !2, 'setAttribute'
          9        SEND_VAL_EX                                              'href'
         10        SEND_VAL_EX                                              '%2Foffline-bcu%2Fdelete%2F12345'
         11        DO_FCALL                                      0          
   20    12        INIT_METHOD_CALL                                         !2, 'setAttribute'
         13        SEND_VAL_EX                                              'class'
         14        SEND_VAL_EX                                              'ml5+mr5+btn+btn-sm+btn-danger'
         15        DO_FCALL                                      0          
   21    16        INIT_FCALL                                               'createnodesfromhtml'
         17        SEND_VAR                                                 !0
         18        SEND_VAR                                                 !1
         19        DO_FCALL                                      0  $12     
         20        ASSIGN                                                   !3, $12
   22    21        INIT_METHOD_CALL                                         !2, 'appendChild'
         22        CHECK_FUNC_ARG                                           
         23        FETCH_DIM_FUNC_ARG                               $14     !3, 0
         24        SEND_FUNC_ARG                                            $14
         25        DO_FCALL                                      0          
   23    26        INIT_METHOD_CALL                                         !0, 'appendChild'
         27        SEND_VAR_EX                                              !2
         28        DO_FCALL                                      0          
   24    29        INIT_METHOD_CALL                                         !0, 'saveHTML'
         30        DO_FCALL                                      0  $17     
         31        ECHO                                                     $17
         32      > RETURN                                                   1

Function createnodesfromhtml:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 16
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 16
Branch analysis from position: 25
Branch analysis from position: 16
filename:       /in/s0UPJ
function name:  createNodesFromHTML
number of ops:  27
compiled vars:  !0 = $doc, !1 = $str, !2 = $nodes, !3 = $d, !4 = $child
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        ASSIGN                                                   !2, <array>
    5     3        NEW                                              $6      'DOMDocument'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !3, $6
    6     6        INIT_METHOD_CALL                                         !3, 'loadHTML'
          7        ROPE_INIT                                     3  ~10     '%3Chtml%3E'
          8        ROPE_ADD                                      1  ~10     ~10, !1
          9        ROPE_END                                      2  ~9      ~10, '%3C%2Fhtml%3E'
         10        SEND_VAL_EX                                              ~9
         11        DO_FCALL                                      0          
    7    12        FETCH_OBJ_R                                      ~13     !3, 'documentElement'
         13        FETCH_OBJ_R                                      ~14     ~13, 'firstChild'
         14        ASSIGN                                                   !4, ~14
    8    15      > JMP                                                      ->24
    9    16    >   INIT_METHOD_CALL                                         !0, 'importNode'
         17        SEND_VAR_EX                                              !4
         18        SEND_VAL_EX                                              <true>
         19        DO_FCALL                                      0  $17     
         20        ASSIGN_DIM                                               !2
         21        OP_DATA                                                  $17
   10    22        FETCH_OBJ_R                                      ~18     !4, 'nextSibling'
         23        ASSIGN                                                   !4, ~18
    8    24    > > JMPNZ                                                    !4, ->16
   12    25    > > RETURN                                                   !2
   13    26*     > RETURN                                                   null

End of function createnodesfromhtml

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169.67 ms | 1403 KiB | 14 Q