3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = '<table id="transactions" class="table"> <thead> <tr> <th class="image"></th> <th class="title"><span>Title</span></th> <th class="date"><span>Date</span></th> </tr> </thead> <tbody> <tr class="tbody-tr"> <td class="image"> <img src="http://www.example.com/image.jpg"> </td> <td class="title">Title </td> <td class="date">12/16/2017 </td> </tr> <tr class="tbody-tr"> <td class="image"> <img src="http://www.example.com/image.jpg"> </td> <td class="title">Title </td> <td class="date">12/16/2017 </td> </tr> </tbody> </table>'; $doc = new DOMDocument(); $doc->loadHTML($html); $doc->formatOutput = true; foreach ($doc->getElementsByTagName('tr') as $tr) { // insert into thead > th if ($tr->childNodes->item(0)->nodeName == 'th') { $th = $doc->createElement('th'); $th->setAttribute('class', 'example'); $th->nodeValue = 'Example'; $tr->insertBefore($th, $tr->childNodes->item(3)); } // insert into body > td else { $td = $doc->createElement('td'); $td->setAttribute('class', 'example'); $tr->insertBefore($td, $tr->childNodes->item(3)); } } echo $doc->saveHTML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 57
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 57
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 40
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 56
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 57
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 57
filename:       /in/1sj7s
function name:  (null)
number of ops:  62
compiled vars:  !0 = $html, !1 = $doc, !2 = $tr, !3 = $th, !4 = $td
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%3Ctable+id%3D%22transactions%22+class%3D%22table%22%3E%0A++++%3Cthead%3E%0A++++++++%3Ctr%3E%0A++++++++++++%3Cth+class%3D%22image%22%3E%3C%2Fth%3E%0A++++++++++++%3Cth+class%3D%22title%22%3E%3Cspan%3ETitle%3C%2Fspan%3E%3C%2Fth%3E%0A++++++++++++%3Cth+class%3D%22date%22%3E%3Cspan%3EDate%3C%2Fspan%3E%3C%2Fth%3E%0A++++++++%3C%2Ftr%3E%0A++++%3C%2Fthead%3E%0A++++%3Ctbody%3E%0A++++++++%3Ctr+class%3D%22tbody-tr%22%3E%0A++++++++++++%3Ctd+class%3D%22image%22%3E%0A++++++++++++++++%3Cimg+src%3D%22http%3A%2F%2Fwww.example.com%2Fimage.jpg%22%3E%0A++++++++++++%3C%2Ftd%3E%0A++++++++++++%3Ctd+class%3D%22title%22%3ETitle%0A++++++++++++%3C%2Ftd%3E%0A++++++++++++%3Ctd+class%3D%22date%22%3E12%2F16%2F2017%0A++++++++++++%3C%2Ftd%3E%0A++++++++%3C%2Ftr%3E%0A++++++++%3Ctr+class%3D%22tbody-tr%22%3E%0A++++++++++++%3Ctd+class%3D%22image%22%3E%0A++++++++++++++++%3Cimg+src%3D%22http%3A%2F%2Fwww.example.com%2Fimage.jpg%22%3E%0A++++++++++++%3C%2Ftd%3E%0A++++++++++++%3Ctd+class%3D%22title%22%3ETitle%0A++++++++++++%3C%2Ftd%3E%0A++++++++++++%3Ctd+class%3D%22date%22%3E12%2F16%2F2017%0A++++++++++++%3C%2Ftd%3E%0A++++++++%3C%2Ftr%3E%0A++++%3C%2Ftbody%3E%0A%3C%2Ftable%3E'
   32     1        NEW                                              $6      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $6
   33     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   34     7        ASSIGN_OBJ                                               !1, 'formatOutput'
          8        OP_DATA                                                  <true>
   36     9        INIT_METHOD_CALL                                         !1, 'getElementsByTagName'
         10        SEND_VAL_EX                                              'tr'
         11        DO_FCALL                                      0  $11     
         12      > FE_RESET_R                                       $12     $11, ->57
         13    > > FE_FETCH_R                                               $12, !2, ->57
   39    14    >   FETCH_OBJ_R                                      ~13     !2, 'childNodes'
         15        INIT_METHOD_CALL                                         ~13, 'item'
         16        SEND_VAL_EX                                              0
         17        DO_FCALL                                      0  $14     
         18        FETCH_OBJ_R                                      ~15     $14, 'nodeName'
         19        IS_EQUAL                                                 ~15, 'th'
         20      > JMPZ                                                     ~16, ->40
   40    21    >   INIT_METHOD_CALL                                         !1, 'createElement'
         22        SEND_VAL_EX                                              'th'
         23        DO_FCALL                                      0  $17     
         24        ASSIGN                                                   !3, $17
   41    25        INIT_METHOD_CALL                                         !3, 'setAttribute'
         26        SEND_VAL_EX                                              'class'
         27        SEND_VAL_EX                                              'example'
         28        DO_FCALL                                      0          
   42    29        ASSIGN_OBJ                                               !3, 'nodeValue'
         30        OP_DATA                                                  'Example'
   43    31        INIT_METHOD_CALL                                         !2, 'insertBefore'
         32        SEND_VAR_EX                                              !3
         33        FETCH_OBJ_R                                      ~21     !2, 'childNodes'
         34        INIT_METHOD_CALL                                         ~21, 'item'
         35        SEND_VAL_EX                                              3
         36        DO_FCALL                                      0  $22     
         37        SEND_VAR_NO_REF_EX                                       $22
         38        DO_FCALL                                      0          
         39      > JMP                                                      ->56
   47    40    >   INIT_METHOD_CALL                                         !1, 'createElement'
         41        SEND_VAL_EX                                              'td'
         42        DO_FCALL                                      0  $24     
         43        ASSIGN                                                   !4, $24
   48    44        INIT_METHOD_CALL                                         !4, 'setAttribute'
         45        SEND_VAL_EX                                              'class'
         46        SEND_VAL_EX                                              'example'
         47        DO_FCALL                                      0          
   50    48        INIT_METHOD_CALL                                         !2, 'insertBefore'
         49        SEND_VAR_EX                                              !4
         50        FETCH_OBJ_R                                      ~27     !2, 'childNodes'
         51        INIT_METHOD_CALL                                         ~27, 'item'
         52        SEND_VAL_EX                                              3
         53        DO_FCALL                                      0  $28     
         54        SEND_VAR_NO_REF_EX                                       $28
         55        DO_FCALL                                      0          
   36    56    > > JMP                                                      ->13
         57    >   FE_FREE                                                  $12
   54    58        INIT_METHOD_CALL                                         !1, 'saveHTML'
         59        DO_FCALL                                      0  $30     
         60        ECHO                                                     $30
         61      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.86 ms | 1403 KiB | 13 Q