3v4l.org

run code in 300+ PHP versions simultaneously
<?php $res = ' <html> <div class="product bla bla"> <div class="size">xxl</div> <div class="color yy">red</div> </div> <div class="product bla"> <div class="size xxs">xxs</div> <div class="line line2">new</div> </div> <div class="product asd"> <div class="color xx">blue</div> </div> </html> '; $dom = new DomDocument(); @ $dom->loadHTML($res); // utf8_decode $dom->preserveWhiteSpace = false; // ? $xpath = new DomXPath($dom); $nodes = $xpath ->query("//*[contains(@class, 'product')]"); echo "Found {$nodes->length} matching places" . PHP_EOL; foreach($nodes as $node){ $name = $xpath->query("*[contains(@class, 'color')]", $node); echo null === $name[0] ? 'NULL' : $name[0]->nodeValue; echo PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 26, Position 2 = 43
Branch analysis from position: 26
2 jumps found. (Code = 78) Position 1 = 27, Position 2 = 43
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 43
filename:       /in/IQFqd
function name:  (null)
number of ops:  45
compiled vars:  !0 = $res, !1 = $dom, !2 = $xpath, !3 = $nodes, !4 = $node, !5 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%0A%3Chtml%3E%0A%3Cdiv+class%3D%22product+bla+bla%22%3E%0A%3Cdiv+class%3D%22size%22%3Exxl%3C%2Fdiv%3E%0A%3Cdiv+class%3D%22color+yy%22%3Ered%3C%2Fdiv%3E%0A%3C%2Fdiv%3E%0A%0A%3Cdiv+class%3D%22product+bla%22%3E%0A%3Cdiv+class%3D%22size+xxs%22%3Exxs%3C%2Fdiv%3E%0A%3Cdiv+class%3D%22line+line2%22%3Enew%3C%2Fdiv%3E%0A%3C%2Fdiv%3E%0A%0A%3Cdiv+class%3D%22product+asd%22%3E%0A%3Cdiv+class%3D%22color+xx%22%3Eblue%3C%2Fdiv%3E%0A%3C%2Fdiv%3E%0A%3C%2Fhtml%3E%0A'
   21     1        NEW                                              $7      'DomDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $7
   22     4        BEGIN_SILENCE                                    ~10     
          5        INIT_METHOD_CALL                                         !1, 'loadHTML'
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0          
          8        END_SILENCE                                              ~10
   23     9        ASSIGN_OBJ                                               !1, 'preserveWhiteSpace'
         10        OP_DATA                                                  <false>
   24    11        NEW                                              $13     'DomXPath'
         12        SEND_VAR_EX                                              !1
         13        DO_FCALL                                      0          
         14        ASSIGN                                                   !2, $13
   25    15        INIT_METHOD_CALL                                         !2, 'query'
         16        SEND_VAL_EX                                              '%2F%2F%2A%5Bcontains%28%40class%2C+%27product%27%29%5D'
         17        DO_FCALL                                      0  $16     
         18        ASSIGN                                                   !3, $16
   27    19        ROPE_INIT                                     3  ~20     'Found+'
         20        FETCH_OBJ_R                                      ~18     !3, 'length'
         21        ROPE_ADD                                      1  ~20     ~20, ~18
         22        ROPE_END                                      2  ~19     ~20, '+matching+places'
         23        CONCAT                                           ~22     ~19, '%0A'
         24        ECHO                                                     ~22
   29    25      > FE_RESET_R                                       $23     !3, ->43
         26    > > FE_FETCH_R                                               $23, !4, ->43
   30    27    >   INIT_METHOD_CALL                                         !2, 'query'
         28        SEND_VAL_EX                                              '%2A%5Bcontains%28%40class%2C+%27color%27%29%5D'
         29        SEND_VAR_EX                                              !4
         30        DO_FCALL                                      0  $24     
         31        ASSIGN                                                   !5, $24
   31    32        FETCH_DIM_R                                      ~26     !5, 0
         33        TYPE_CHECK                                    2          ~26
         34      > JMPZ                                                     ~27, ->37
         35    >   QM_ASSIGN                                        ~28     'NULL'
         36      > JMP                                                      ->40
         37    >   FETCH_DIM_R                                      ~29     !5, 0
         38        FETCH_OBJ_R                                      ~30     ~29, 'nodeValue'
         39        QM_ASSIGN                                        ~28     ~30
         40    >   ECHO                                                     ~28
   32    41        ECHO                                                     '%0A'
   29    42      > JMP                                                      ->26
         43    >   FE_FREE                                                  $23
   34    44      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.3 ms | 1012 KiB | 13 Q