3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<'HTML' <body> <main> <div> Lorem ipsum dolor sit amet consectetur adipisicing elit. </div> <p> Incidunt expedita laudantium aliquid unde explicabo. </p> <span> Velit eveniet alias minima vitae libero labore. </span> </main> </body> HTML; $dom = new DOMDocument; @$dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $xpath = new DomXPath($dom); $entry = $xpath->query('//main/node()'); $content = ''; foreach($entry as $element) { $content .= $dom->saveHTML($element); } ///////////////////////////////////////////////////////////////////////////////// // Как дальше искать внутри переменной «$content» (без xPath) ? ///////////////////////////////////////////////////////////////////////////////// $subcontent = ''; foreach($content->getElementsByTagName('*') as $node) { $subcontent .= $dom->saveHTML($node); } echo $subcontent; // не работает
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 26
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 26
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 26
2 jumps found. (Code = 77) Position 1 = 32, Position 2 = 38
Branch analysis from position: 32
2 jumps found. (Code = 78) Position 1 = 33, Position 2 = 38
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
Branch analysis from position: 26
filename:       /in/pqjvP
function name:  (null)
number of ops:  41
compiled vars:  !0 = $html, !1 = $dom, !2 = $xpath, !3 = $entry, !4 = $content, !5 = $element, !6 = $subcontent, !7 = $node
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Cbody%3E%0A++%3Cmain%3E%0A++++%3Cdiv%3E%0A++++++Lorem+ipsum+dolor+sit+amet+consectetur+adipisicing+elit.%0A++++%3C%2Fdiv%3E%0A++++%3Cp%3E%0A++++++Incidunt+expedita+laudantium+aliquid+unde+explicabo.%0A++++%3C%2Fp%3E%0A++++%3Cspan%3E%0A++++++Velit+eveniet+alias+minima+vitae+libero+labore.%0A++++%3C%2Fspan%3E%0A++%3C%2Fmain%3E%0A%3C%2Fbody%3E'
   19     1        NEW                                              $9      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $9
   20     4        BEGIN_SILENCE                                    ~12     
          5        INIT_METHOD_CALL                                         !1, 'loadHTML'
          6        SEND_VAR_EX                                              !0
          7        SEND_VAL_EX                                              8196
          8        DO_FCALL                                      0          
          9        END_SILENCE                                              ~12
   21    10        NEW                                              $14     'DomXPath'
         11        SEND_VAR_EX                                              !1
         12        DO_FCALL                                      0          
         13        ASSIGN                                                   !2, $14
   22    14        INIT_METHOD_CALL                                         !2, 'query'
         15        SEND_VAL_EX                                              '%2F%2Fmain%2Fnode%28%29'
         16        DO_FCALL                                      0  $17     
         17        ASSIGN                                                   !3, $17
   24    18        ASSIGN                                                   !4, ''
   25    19      > FE_RESET_R                                       $20     !3, ->26
         20    > > FE_FETCH_R                                               $20, !5, ->26
   26    21    >   INIT_METHOD_CALL                                         !1, 'saveHTML'
         22        SEND_VAR_EX                                              !5
         23        DO_FCALL                                      0  $21     
         24        ASSIGN_OP                                     8          !4, $21
   25    25      > JMP                                                      ->20
         26    >   FE_FREE                                                  $20
   33    27        ASSIGN                                                   !6, ''
   34    28        INIT_METHOD_CALL                                         !4, 'getElementsByTagName'
         29        SEND_VAL_EX                                              '%2A'
         30        DO_FCALL                                      0  $24     
         31      > FE_RESET_R                                       $25     $24, ->38
         32    > > FE_FETCH_R                                               $25, !7, ->38
   35    33    >   INIT_METHOD_CALL                                         !1, 'saveHTML'
         34        SEND_VAR_EX                                              !7
         35        DO_FCALL                                      0  $26     
         36        ASSIGN_OP                                     8          !6, $26
   34    37      > JMP                                                      ->32
         38    >   FE_FREE                                                  $25
   37    39        ECHO                                                     !6
         40      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
182.2 ms | 1403 KiB | 13 Q