3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <!DOCTYPE html> <html> <head> <title></title> </head> <body> <table class="table-list table table-responsive table-striped" border="1"> <thead> <tr> <th class="coll-1 name">name</th> <th class="coll-2">height</th> <th class="coll-3">weight</th> <th class="coll-date">date</th> <th class="coll-4"><span class="info">info</span></th> <th class="coll-5">country</th> </tr> </thead> <tbody> <tr> <td class="coll-1 name"> <a href="/username/Jhon Doe/" class="icon"><i class="flaticon-user"></i></a> <a href="/username/Jhon Doe/">Jhon Doe</a> </td> <td class="coll-2 height">45</td> <td class="coll-3 weight">50</td> <td class="coll-date">9am May. 16th</td> <td class="coll-4 size mob-info">abcd</td> <td class="coll-5 country"><a href="/country/CA/">CA</a></td> </tr> <tr> <td class="coll-1 name"> <a href="/username/Kasim Shk/" class="icon"><i class="flaticon-user"></i></a> <a href="/username/Kasim Shk/">Kasim Shk</a> </td> <td class="coll-2 height">33</td> <td class="coll-3 weight">54</td> <td class="coll-date">Mar. 14th '18</td> <td class="coll-4 size mob-info">ijkl</td> <td class="coll-5 country"><a href="/country/UAE/">UAE</a></td> </tr> </tbody> </table> </body> </html> HTML; $dom = new DOMDocument; $dom->loadHTML($html); $xpath = new DOMXPath($dom); foreach ($xpath->query('//tbody/tr') as $tr) { $tmp = []; // reset the temporary array so previous entries are removed foreach ($xpath->query("td[@class]", $tr) as $td) { $key = preg_match('~[a-z]+$~', $td->getAttribute('class'), $out) ? $out[0] : 'no_class'; if ($key === "name") { $tmp['user_link'] = $xpath->query("a[@class = 'icon']", $td)[0]->getAttribute('href'); } $tmp[$key] = trim($td->textContent); } $tmp['date'] = date("M. dS 'y", strtotime(preg_replace('~\.|\d+[ap]m *~', '', $tmp['date']))); $result[] = $tmp; } var_export($result); echo "\n----\n"; echo json_encode($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 75
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 75
Branch analysis from position: 16
2 jumps found. (Code = 77) Position 1 = 22, Position 2 = 56
Branch analysis from position: 22
2 jumps found. (Code = 78) Position 1 = 23, Position 2 = 56
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 35
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 49
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 49
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 49
Branch analysis from position: 39
Branch analysis from position: 49
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 56
Branch analysis from position: 75
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 75
filename:       /in/nHKef
function name:  (null)
number of ops:  85
compiled vars:  !0 = $html, !1 = $dom, !2 = $xpath, !3 = $tr, !4 = $tmp, !5 = $td, !6 = $key, !7 = $out, !8 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%3C%21DOCTYPE+html%3E%0A%3Chtml%3E%0A%3Chead%3E%0A%09%3Ctitle%3E%3C%2Ftitle%3E%0A%3C%2Fhead%3E%0A%3Cbody%3E%0A%0A%3Ctable+class%3D%22table-list+table+table-responsive+table-striped%22+border%3D%221%22%3E%0A%3Cthead%3E%0A%09%3Ctr%3E%0A%09%09%3Cth+class%3D%22coll-1+name%22%3Ename%3C%2Fth%3E%0A%09%09%3Cth+class%3D%22coll-2%22%3Eheight%3C%2Fth%3E%0A%09%09%3Cth+class%3D%22coll-3%22%3Eweight%3C%2Fth%3E%0A%09%09%3Cth+class%3D%22coll-date%22%3Edate%3C%2Fth%3E%0A%09%09%3Cth+class%3D%22coll-4%22%3E%3Cspan+class%3D%22info%22%3Einfo%3C%2Fspan%3E%3C%2Fth%3E%0A%09%09%3Cth+class%3D%22coll-5%22%3Ecountry%3C%2Fth%3E%0A%09%3C%2Ftr%3E%0A%3C%2Fthead%3E%0A%3Ctbody%3E%0A%3Ctr%3E%0A%09%3Ctd+class%3D%22coll-1+name%22%3E%0A%09%09%3Ca+href%3D%22%2Fusername%2FJhon+Doe%2F%22+class%3D%22icon%22%3E%3Ci+class%3D%22flaticon-user%22%3E%3C%2Fi%3E%3C%2Fa%3E%0A%09%09%3Ca+href%3D%22%2Fusername%2FJhon+Doe%2F%22%3EJhon+Doe%3C%2Fa%3E%0A%09%3C%2Ftd%3E%0A%09%3Ctd+class%3D%22coll-2+height%22%3E45%3C%2Ftd%3E%0A%09%3Ctd+class%3D%22coll-3+weight%22%3E50%3C%2Ftd%3E%0A%09%3Ctd+class%3D%22coll-date%22%3E9am+May.+16th%3C%2Ftd%3E%0A%09%3Ctd+class%3D%22coll-4+size+mob-info%22%3Eabcd%3C%2Ftd%3E%0A%09%3Ctd+class%3D%22coll-5+country%22%3E%3Ca+href%3D%22%2Fcountry%2FCA%2F%22%3ECA%3C%2Fa%3E%3C%2Ftd%3E%0A%3C%2Ftr%3E%0A%3Ctr%3E%0A%09%3Ctd+class%3D%22coll-1+name%22%3E%0A%09%09%3Ca+href%3D%22%2Fusername%2FKasim+Shk%2F%22+class%3D%22icon%22%3E%3Ci+class%3D%22flaticon-user%22%3E%3C%2Fi%3E%3C%2Fa%3E%0A%09%09%3Ca+href%3D%22%2Fusername%2FKasim+Shk%2F%22%3EKasim+Shk%3C%2Fa%3E%0A%09%3C%2Ftd%3E%0A%09%3Ctd+class%3D%22coll-2+height%22%3E33%3C%2Ftd%3E%0A%09%3Ctd+class%3D%22coll-3+weight%22%3E54%3C%2Ftd%3E%0A%09%3Ctd+class%3D%22coll-date%22%3EMar.+14th+%2718%3C%2Ftd%3E%0A%09%3Ctd+class%3D%22coll-4+size+mob-info%22%3Eijkl%3C%2Ftd%3E%0A%09%3Ctd+class%3D%22coll-5+country%22%3E%3Ca+href%3D%22%2Fcountry%2FUAE%2F%22%3EUAE%3C%2Fa%3E%3C%2Ftd%3E%0A%3C%2Ftr%3E%0A%3C%2Ftbody%3E%0A%3C%2Ftable%3E%0A%0A%3C%2Fbody%3E%0A%3C%2Fhtml%3E'
   51     1        NEW                                              $10     'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $10
   52     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   53     7        NEW                                              $14     'DOMXPath'
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !2, $14
   54    11        INIT_METHOD_CALL                                         !2, 'query'
         12        SEND_VAL_EX                                              '%2F%2Ftbody%2Ftr'
         13        DO_FCALL                                      0  $17     
         14      > FE_RESET_R                                       $18     $17, ->75
         15    > > FE_FETCH_R                                               $18, !3, ->75
   55    16    >   ASSIGN                                                   !4, <array>
   56    17        INIT_METHOD_CALL                                         !2, 'query'
         18        SEND_VAL_EX                                              'td%5B%40class%5D'
         19        SEND_VAR_EX                                              !3
         20        DO_FCALL                                      0  $20     
         21      > FE_RESET_R                                       $21     $20, ->56
         22    > > FE_FETCH_R                                               $21, !5, ->56
   57    23    >   INIT_FCALL                                               'preg_match'
         24        SEND_VAL                                                 '%7E%5Ba-z%5D%2B%24%7E'
         25        INIT_METHOD_CALL                                         !5, 'getAttribute'
         26        SEND_VAL_EX                                              'class'
         27        DO_FCALL                                      0  $22     
         28        SEND_VAR                                                 $22
         29        SEND_REF                                                 !7
         30        DO_ICALL                                         $23     
         31      > JMPZ                                                     $23, ->35
         32    >   FETCH_DIM_R                                      ~24     !7, 0
         33        QM_ASSIGN                                        ~25     ~24
         34      > JMP                                                      ->36
         35    >   QM_ASSIGN                                        ~25     'no_class'
         36    >   ASSIGN                                                   !6, ~25
   58    37        IS_IDENTICAL                                             !6, 'name'
         38      > JMPZ                                                     ~27, ->49
   59    39    >   INIT_METHOD_CALL                                         !2, 'query'
         40        SEND_VAL_EX                                              'a%5B%40class+%3D+%27icon%27%5D'
         41        SEND_VAR_EX                                              !5
         42        DO_FCALL                                      0  $29     
         43        FETCH_DIM_R                                      ~30     $29, 0
         44        INIT_METHOD_CALL                                         ~30, 'getAttribute'
         45        SEND_VAL_EX                                              'href'
         46        DO_FCALL                                      0  $31     
         47        ASSIGN_DIM                                               !4, 'user_link'
         48        OP_DATA                                                  $31
   61    49    >   INIT_FCALL                                               'trim'
         50        FETCH_OBJ_R                                      ~33     !5, 'textContent'
         51        SEND_VAL                                                 ~33
         52        DO_ICALL                                         $34     
         53        ASSIGN_DIM                                               !4, !6
         54        OP_DATA                                                  $34
   56    55      > JMP                                                      ->22
         56    >   FE_FREE                                                  $21
   63    57        INIT_FCALL                                               'date'
         58        SEND_VAL                                                 'M.+dS+%27y'
         59        INIT_FCALL                                               'strtotime'
         60        INIT_FCALL                                               'preg_replace'
         61        SEND_VAL                                                 '%7E%5C.%7C%5Cd%2B%5Bap%5Dm+%2A%7E'
         62        SEND_VAL                                                 ''
         63        FETCH_DIM_R                                      ~36     !4, 'date'
         64        SEND_VAL                                                 ~36
         65        DO_ICALL                                         $37     
         66        SEND_VAR                                                 $37
         67        DO_ICALL                                         $38     
         68        SEND_VAR                                                 $38
         69        DO_ICALL                                         $39     
         70        ASSIGN_DIM                                               !4, 'date'
         71        OP_DATA                                                  $39
   64    72        ASSIGN_DIM                                               !8
         73        OP_DATA                                                  !4
   54    74      > JMP                                                      ->15
         75    >   FE_FREE                                                  $18
   66    76        INIT_FCALL                                               'var_export'
         77        SEND_VAR                                                 !8
         78        DO_ICALL                                                 
   67    79        ECHO                                                     '%0A----%0A'
   68    80        INIT_FCALL                                               'json_encode'
         81        SEND_VAR                                                 !8
         82        DO_ICALL                                         $42     
         83        ECHO                                                     $42
         84      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.93 ms | 1475 KiB | 20 Q