3v4l.org

run code in 300+ PHP versions simultaneously
<?php $cssClasses = [ 'container' => 'width: 100%;padding-right: 15px;padding-left: 15px;margin-right: auto;margin-left: auto;', 'card' => 'position: relative;display: -ms-flexbox;display: flex;-ms-flex-direction: column;flex-direction: column;min-width: 0;word-wrap: break-word;background-color: #fff;background-clip: border-box;border: 1px solid rgba(0, 0, 0, 0.125);border-radius: 0.25rem;' ]; $html = <<<'EOD' <div class="container"> 01 <div class="card"> 02 </div> </div> EOD; $dom = new DOMDocument; $dom->loadHTML($html); $divNL = $dom->getElementsByTagName('div'); for ($i = $divNL->length - 1; $i >= 0; $i--) { $node = $divNL->item($i); $table = $dom->createElement('table'); $tr = $dom->createElement('tr'); $td = $dom->createElement('td'); $table->appendChild($tr); $tr->appendChild($td); foreach ($node->attributes as $attr) { $td->appendChild($attr); } $styles = array_reduce( preg_split('~\s+~u', $td->getAttribute('class')), function($c, $i) use ($cssClasses) { return isset($cssClasses[$i]) ? $cssClasses[$i] . $c : $c; }, $td->getAttribute('style') ); if ( !empty($styles) ) $td->setAttribute('style', $styles); foreach ($node->childNodes as $childNode) { $td->appendChild($childNode->cloneNode(true)); } $node->parentNode->replaceChild($table, $node); } $result = ''; foreach ($dom->getElementsByTagName('body')->item(0)->childNodes as $childNode) { $result .= $dom->saveHTML($childNode); } echo $result;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 88
Branch analysis from position: 88
2 jumps found. (Code = 44) Position 1 = 90, Position 2 = 16
Branch analysis from position: 90
2 jumps found. (Code = 77) Position 1 = 99, Position 2 = 105
Branch analysis from position: 99
2 jumps found. (Code = 78) Position 1 = 100, Position 2 = 105
Branch analysis from position: 100
1 jumps found. (Code = 42) Position 1 = 99
Branch analysis from position: 99
Branch analysis from position: 105
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 105
Branch analysis from position: 16
2 jumps found. (Code = 77) Position 1 = 40, Position 2 = 45
Branch analysis from position: 40
2 jumps found. (Code = 78) Position 1 = 41, Position 2 = 45
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 67, Position 2 = 71
Branch analysis from position: 67
2 jumps found. (Code = 77) Position 1 = 73, Position 2 = 81
Branch analysis from position: 73
2 jumps found. (Code = 78) Position 1 = 74, Position 2 = 81
Branch analysis from position: 74
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
Branch analysis from position: 81
2 jumps found. (Code = 44) Position 1 = 90, Position 2 = 16
Branch analysis from position: 90
Branch analysis from position: 16
Branch analysis from position: 81
Branch analysis from position: 71
Branch analysis from position: 45
filename:       /in/sAWll
function name:  (null)
number of ops:  108
compiled vars:  !0 = $cssClasses, !1 = $html, !2 = $dom, !3 = $divNL, !4 = $i, !5 = $node, !6 = $table, !7 = $tr, !8 = $td, !9 = $attr, !10 = $styles, !11 = $childNode, !12 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    7     1        ASSIGN                                                   !1, '%3Cdiv+class%3D%22container%22%3E%0A++++01%0A++++%3Cdiv+class%3D%22card%22%3E%0A++++++++02%0A++++%3C%2Fdiv%3E%0A%3C%2Fdiv%3E'
   16     2        NEW                                              $15     'DOMDocument'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !2, $15
   17     5        INIT_METHOD_CALL                                         !2, 'loadHTML'
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0          
   19     8        INIT_METHOD_CALL                                         !2, 'getElementsByTagName'
          9        SEND_VAL_EX                                              'div'
         10        DO_FCALL                                      0  $19     
         11        ASSIGN                                                   !3, $19
   21    12        FETCH_OBJ_R                                      ~21     !3, 'length'
         13        SUB                                              ~22     ~21, 1
         14        ASSIGN                                                   !4, ~22
         15      > JMP                                                      ->88
   22    16    >   INIT_METHOD_CALL                                         !3, 'item'
         17        SEND_VAR_EX                                              !4
         18        DO_FCALL                                      0  $24     
         19        ASSIGN                                                   !5, $24
   24    20        INIT_METHOD_CALL                                         !2, 'createElement'
         21        SEND_VAL_EX                                              'table'
         22        DO_FCALL                                      0  $26     
         23        ASSIGN                                                   !6, $26
   25    24        INIT_METHOD_CALL                                         !2, 'createElement'
         25        SEND_VAL_EX                                              'tr'
         26        DO_FCALL                                      0  $28     
         27        ASSIGN                                                   !7, $28
   26    28        INIT_METHOD_CALL                                         !2, 'createElement'
         29        SEND_VAL_EX                                              'td'
         30        DO_FCALL                                      0  $30     
         31        ASSIGN                                                   !8, $30
   27    32        INIT_METHOD_CALL                                         !6, 'appendChild'
         33        SEND_VAR_EX                                              !7
         34        DO_FCALL                                      0          
   28    35        INIT_METHOD_CALL                                         !7, 'appendChild'
         36        SEND_VAR_EX                                              !8
         37        DO_FCALL                                      0          
   30    38        FETCH_OBJ_R                                      ~34     !5, 'attributes'
         39      > FE_RESET_R                                       $35     ~34, ->45
         40    > > FE_FETCH_R                                               $35, !9, ->45
   31    41    >   INIT_METHOD_CALL                                         !8, 'appendChild'
         42        SEND_VAR_EX                                              !9
         43        DO_FCALL                                      0          
   30    44      > JMP                                                      ->40
         45    >   FE_FREE                                                  $35
   34    46        INIT_FCALL                                               'array_reduce'
   35    47        INIT_FCALL                                               'preg_split'
         48        SEND_VAL                                                 '%7E%5Cs%2B%7Eu'
         49        INIT_METHOD_CALL                                         !8, 'getAttribute'
         50        SEND_VAL_EX                                              'class'
         51        DO_FCALL                                      0  $37     
         52        SEND_VAR                                                 $37
         53        DO_ICALL                                         $38     
         54        SEND_VAR                                                 $38
   36    55        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FsAWll%3A36%240'
         56        BIND_LEXICAL                                             ~39, !0
   38    57        SEND_VAL                                                 ~39
   39    58        INIT_METHOD_CALL                                         !8, 'getAttribute'
         59        SEND_VAL_EX                                              'style'
         60        DO_FCALL                                      0  $40     
         61        SEND_VAR                                                 $40
         62        DO_ICALL                                         $41     
   34    63        ASSIGN                                                   !10, $41
   42    64        ISSET_ISEMPTY_CV                                 ~43     !10
         65        BOOL_NOT                                         ~44     ~43
         66      > JMPZ                                                     ~44, ->71
   43    67    >   INIT_METHOD_CALL                                         !8, 'setAttribute'
         68        SEND_VAL_EX                                              'style'
         69        SEND_VAR_EX                                              !10
         70        DO_FCALL                                      0          
   46    71    >   FETCH_OBJ_R                                      ~46     !5, 'childNodes'
         72      > FE_RESET_R                                       $47     ~46, ->81
         73    > > FE_FETCH_R                                               $47, !11, ->81
   47    74    >   INIT_METHOD_CALL                                         !8, 'appendChild'
         75        INIT_METHOD_CALL                                         !11, 'cloneNode'
         76        SEND_VAL_EX                                              <true>
         77        DO_FCALL                                      0  $48     
         78        SEND_VAR_NO_REF_EX                                       $48
         79        DO_FCALL                                      0          
   46    80      > JMP                                                      ->73
         81    >   FE_FREE                                                  $47
   50    82        FETCH_OBJ_R                                      ~50     !5, 'parentNode'
         83        INIT_METHOD_CALL                                         ~50, 'replaceChild'
         84        SEND_VAR_EX                                              !6
         85        SEND_VAR_EX                                              !5
         86        DO_FCALL                                      0          
   21    87        PRE_DEC                                                  !4
         88    >   IS_SMALLER_OR_EQUAL                                      0, !4
         89      > JMPNZ                                                    ~53, ->16
   54    90    >   ASSIGN                                                   !12, ''
   56    91        INIT_METHOD_CALL                                         !2, 'getElementsByTagName'
         92        SEND_VAL_EX                                              'body'
         93        DO_FCALL                                      0  $55     
         94        INIT_METHOD_CALL                                         $55, 'item'
         95        SEND_VAL_EX                                              0
         96        DO_FCALL                                      0  $56     
         97        FETCH_OBJ_R                                      ~57     $56, 'childNodes'
         98      > FE_RESET_R                                       $58     ~57, ->105
         99    > > FE_FETCH_R                                               $58, !11, ->105
   57   100    >   INIT_METHOD_CALL                                         !2, 'saveHTML'
        101        SEND_VAR_EX                                              !11
        102        DO_FCALL                                      0  $59     
        103        ASSIGN_OP                                     8          !12, $59
   56   104      > JMP                                                      ->99
        105    >   FE_FREE                                                  $58
   60   106        ECHO                                                     !12
   61   107      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FsAWll%3A36%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sAWll
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $c, !1 = $i, !2 = $cssClasses
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   37     3        ISSET_ISEMPTY_DIM_OBJ                         0          !2, !1
          4      > JMPZ                                                     ~3, ->9
          5    >   FETCH_DIM_R                                      ~4      !2, !1
          6        CONCAT                                           ~5      ~4, !0
          7        QM_ASSIGN                                        ~6      ~5
          8      > JMP                                                      ->10
          9    >   QM_ASSIGN                                        ~6      !0
         10    > > RETURN                                                   ~6
   38    11*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FsAWll%3A36%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
189.04 ms | 1408 KiB | 17 Q