3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @link http://stackoverflow.com/a/23543493/367456 */ $html = '<body>... <th class="name" align="left" scope="col"> <a class="foo" href="foo.html">foo</a> </th> ... <th class="name" align="left" scope="col"> <a class="bar" href="bar.html">bar</a> </th> ... <th class="name" align="left" scope="col"> <a class="ba" href="baz.html">baz</a> </th></body>'; $names = function($html) { $doc = new DOMDocument(); $last = libxml_use_internal_errors(TRUE); $doc->loadHTML($html); libxml_use_internal_errors($last); $xp = new DOMXPath($doc); $result = []; foreach ($xp->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' name ')]") as $node) $result[trim($node->textContent)] = 1; return array_keys($result); }; echo json_encode(["names" => $names($html)]);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QYU0a
function name:  (null)
number of ops:  12
compiled vars:  !0 = $html, !1 = $names
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   ASSIGN                                                   !0, '%3Cbody%3E...%0A%3Cth+class%3D%22name%22+align%3D%22left%22+scope%3D%22col%22%3E%0A%3Ca+class%3D%22foo%22+href%3D%22foo.html%22%3Efoo%3C%2Fa%3E%0A%3C%2Fth%3E%0A...%0A%3Cth+class%3D%22name%22+align%3D%22left%22+scope%3D%22col%22%3E%0A%3Ca+class%3D%22bar%22+href%3D%22bar.html%22%3Ebar%3C%2Fa%3E%0A%3C%2Fth%3E%0A...%0A%3Cth+class%3D%22name%22+align%3D%22left%22+scope%3D%22col%22%3E%0A%3Ca+class%3D%22ba%22+href%3D%22baz.html%22%3Ebaz%3C%2Fa%3E%0A%3C%2Fth%3E%3C%2Fbody%3E'
   19     1        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FQYU0a%3A19%240'
          2        ASSIGN                                                   !1, ~3
   31     3        INIT_FCALL                                               'json_encode'
          4        INIT_DYNAMIC_CALL                                        !1
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0  $5      
          7        INIT_ARRAY                                       ~6      $5, 'names'
          8        SEND_VAL                                                 ~6
          9        DO_ICALL                                         $7      
         10        ECHO                                                     $7
         11      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FQYU0a%3A19%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 31
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 31
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/QYU0a
function name:  {closure}
number of ops:  37
compiled vars:  !0 = $html, !1 = $doc, !2 = $last, !3 = $xp, !4 = $result, !5 = $node
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   20     1        NEW                                              $6      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $6
   21     4        INIT_FCALL                                               'libxml_use_internal_errors'
          5        SEND_VAL                                                 <true>
          6        DO_ICALL                                         $9      
          7        ASSIGN                                                   !2, $9
   22     8        INIT_METHOD_CALL                                         !1, 'loadHTML'
          9        SEND_VAR_EX                                              !0
         10        DO_FCALL                                      0          
   23    11        INIT_FCALL                                               'libxml_use_internal_errors'
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                                 
   24    14        NEW                                              $13     'DOMXPath'
         15        SEND_VAR_EX                                              !1
         16        DO_FCALL                                      0          
         17        ASSIGN                                                   !3, $13
   25    18        ASSIGN                                                   !4, <array>
   26    19        INIT_METHOD_CALL                                         !3, 'query'
         20        SEND_VAL_EX                                              '%2F%2F%2A%5Bcontains%28concat%28%27+%27%2C+normalize-space%28%40class%29%2C+%27+%27%29%2C+%27+name+%27%29%5D'
         21        DO_FCALL                                      0  $17     
         22      > FE_RESET_R                                       $18     $17, ->31
         23    > > FE_FETCH_R                                               $18, !5, ->31
   27    24    >   INIT_FCALL                                               'trim'
         25        FETCH_OBJ_R                                      ~19     !5, 'textContent'
         26        SEND_VAL                                                 ~19
         27        DO_ICALL                                         $20     
         28        ASSIGN_DIM                                               !4, $20
         29        OP_DATA                                                  1
   26    30      > JMP                                                      ->23
         31    >   FE_FREE                                                  $18
   28    32        INIT_FCALL                                               'array_keys'
         33        SEND_VAR                                                 !4
         34        DO_ICALL                                         $22     
         35      > RETURN                                                   $22
   29    36*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FQYU0a%3A19%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.25 ms | 1404 KiB | 22 Q