3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = '<!DOCTYPE html> <title>Valid HTML5 Document</title> <p>Paragraph 1</p> <script>console.log("</html>Console log text");</script> <p>Paragraph 2</p>'; // DOMDocument (libxml) $dom = new DOMDocument('1.0', 'UTF-8'); $dom->formatOutput = true; $dom->loadHtml($html); $paragraphs = $dom->getElementsByTagName('p'); echo "\n"; echo "DOMDocument parsing (libxml)\n"; echo "----------------------------\n"; echo "{$paragraphs->length} paragraph elements found:\n"; // 3 paragraphs found (incorrect) foreach ($paragraphs as $p) { echo " * " . trim($p->textContent) . "\n"; } echo "\n"; echo "DOM serialised:\n"; echo $dom->saveHtml(); // DOM/HTMLDocument (lexbor) $newDom = \DOM\HTMLDocument::createFromString($html); $paragraphs = $newDom->getElementsByTagName('p'); echo "\n"; echo "DOM\HTMLDocument parsing (lexbor)\n"; echo "---------------------------------\n"; echo "{$paragraphs->length} paragraph elements found.\n"; // 2 paragraphs found (correct) foreach ($paragraphs as $p) { echo " * " . trim($p->textContent) . "\n"; } echo "\n"; echo "DOM serialised:\n"; echo $newDom->saveHtml();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 32
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 32
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 32
2 jumps found. (Code = 77) Position 1 = 54, Position 2 = 63
Branch analysis from position: 54
2 jumps found. (Code = 78) Position 1 = 55, Position 2 = 63
Branch analysis from position: 55
1 jumps found. (Code = 42) Position 1 = 54
Branch analysis from position: 54
Branch analysis from position: 63
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 63
Branch analysis from position: 32
filename:       /in/tXp91
function name:  (null)
number of ops:  70
compiled vars:  !0 = $html, !1 = $dom, !2 = $paragraphs, !3 = $p, !4 = $newDom
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%3C%21DOCTYPE+html%3E%0A%3Ctitle%3EValid+HTML5+Document%3C%2Ftitle%3E%0A%3Cp%3EParagraph+1%3C%2Fp%3E%0A%3Cscript%3Econsole.log%28%22%3C%2Fhtml%3EConsole+log+text%22%29%3B%3C%2Fscript%3E%0A%3Cp%3EParagraph+2%3C%2Fp%3E'
    9     1        NEW                                              $6      'DOMDocument'
          2        SEND_VAL_EX                                              '1.0'
          3        SEND_VAL_EX                                              'UTF-8'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $6
   10     6        ASSIGN_OBJ                                               !1, 'formatOutput'
          7        OP_DATA                                                  <true>
   11     8        INIT_METHOD_CALL                                         !1, 'loadHtml'
          9        SEND_VAR_EX                                              !0
         10        DO_FCALL                                      0          
   12    11        INIT_METHOD_CALL                                         !1, 'getElementsByTagName'
         12        SEND_VAL_EX                                              'p'
         13        DO_FCALL                                      0  $11     
         14        ASSIGN                                                   !2, $11
   13    15        ECHO                                                     '%0A'
   14    16        ECHO                                                     'DOMDocument+parsing+%28libxml%29%0A'
   15    17        ECHO                                                     '----------------------------%0A'
   16    18        FETCH_OBJ_R                                      ~13     !2, 'length'
         19        NOP                                                      
         20        FAST_CONCAT                                      ~14     ~13, '+paragraph+elements+found%3A%0A'
         21        ECHO                                                     ~14
   18    22      > FE_RESET_R                                       $15     !2, ->32
         23    > > FE_FETCH_R                                               $15, !3, ->32
   19    24    >   INIT_FCALL                                               'trim'
         25        FETCH_OBJ_R                                      ~16     !3, 'textContent'
         26        SEND_VAL                                                 ~16
         27        DO_ICALL                                         $17     
         28        CONCAT                                           ~18     '+%2A+', $17
         29        CONCAT                                           ~19     ~18, '%0A'
         30        ECHO                                                     ~19
   18    31      > JMP                                                      ->23
         32    >   FE_FREE                                                  $15
   21    33        ECHO                                                     '%0A'
   22    34        ECHO                                                     'DOM+serialised%3A%0A'
   23    35        INIT_METHOD_CALL                                         !1, 'saveHtml'
         36        DO_FCALL                                      0  $20     
         37        ECHO                                                     $20
   26    38        INIT_STATIC_METHOD_CALL                                  'DOM%5CHTMLDocument', 'createFromString'
         39        SEND_VAR_EX                                              !0
         40        DO_FCALL                                      0  $21     
         41        ASSIGN                                                   !4, $21
   27    42        INIT_METHOD_CALL                                         !4, 'getElementsByTagName'
         43        SEND_VAL_EX                                              'p'
         44        DO_FCALL                                      0  $23     
         45        ASSIGN                                                   !2, $23
   28    46        ECHO                                                     '%0A'
   29    47        ECHO                                                     'DOM%5CHTMLDocument+parsing+%28lexbor%29%0A'
   30    48        ECHO                                                     '---------------------------------%0A'
   31    49        FETCH_OBJ_R                                      ~25     !2, 'length'
         50        NOP                                                      
         51        FAST_CONCAT                                      ~26     ~25, '+paragraph+elements+found.%0A'
         52        ECHO                                                     ~26
   33    53      > FE_RESET_R                                       $27     !2, ->63
         54    > > FE_FETCH_R                                               $27, !3, ->63
   34    55    >   INIT_FCALL                                               'trim'
         56        FETCH_OBJ_R                                      ~28     !3, 'textContent'
         57        SEND_VAL                                                 ~28
         58        DO_ICALL                                         $29     
         59        CONCAT                                           ~30     '+%2A+', $29
         60        CONCAT                                           ~31     ~30, '%0A'
         61        ECHO                                                     ~31
   33    62      > JMP                                                      ->54
         63    >   FE_FREE                                                  $27
   36    64        ECHO                                                     '%0A'
   37    65        ECHO                                                     'DOM+serialised%3A%0A'
   38    66        INIT_METHOD_CALL                                         !4, 'saveHtml'
         67        DO_FCALL                                      0  $32     
         68        ECHO                                                     $32
         69      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
124.17 ms | 1456 KiB | 14 Q