3v4l.org

run code in 500+ 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 = 30
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 30
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 30
2 jumps found. (Code = 77) Position 1 = 52, Position 2 = 59
Branch analysis from position: 52
2 jumps found. (Code = 78) Position 1 = 53, Position 2 = 59
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
Branch analysis from position: 59
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 59
Branch analysis from position: 30
filename:       /in/tXp91
function name:  (null)
number of ops:  66
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, ->30
         23    > > FE_FETCH_R                                                   $15, !3, ->30
   19    24    >   FETCH_OBJ_R                                          ~16     !3, 'textContent'
         25        FRAMELESS_ICALL_1                trim                ~17     ~16
         26        CONCAT                                               ~18     '+%2A+', ~17
         27        CONCAT                                               ~19     ~18, '%0A'
         28        ECHO                                                         ~19
   18    29      > JMP                                                          ->23
         30    >   FE_FREE                                                      $15
   21    31        ECHO                                                         '%0A'
   22    32        ECHO                                                         'DOM+serialised%3A%0A'
   23    33        INIT_METHOD_CALL                                             !1, 'saveHtml'
         34        DO_FCALL                                          0  $20     
         35        ECHO                                                         $20
   26    36        INIT_STATIC_METHOD_CALL                                      'DOM%5CHTMLDocument', 'createFromString'
         37        SEND_VAR                                                     !0
         38        DO_FCALL                                          0  $21     
         39        ASSIGN                                                       !4, $21
   27    40        INIT_METHOD_CALL                                             !4, 'getElementsByTagName'
         41        SEND_VAL_EX                                                  'p'
         42        DO_FCALL                                          0  $23     
         43        ASSIGN                                                       !2, $23
   28    44        ECHO                                                         '%0A'
   29    45        ECHO                                                         'DOM%5CHTMLDocument+parsing+%28lexbor%29%0A'
   30    46        ECHO                                                         '---------------------------------%0A'
   31    47        FETCH_OBJ_R                                          ~25     !2, 'length'
         48        NOP                                                          
         49        FAST_CONCAT                                          ~26     ~25, '+paragraph+elements+found.%0A'
         50        ECHO                                                         ~26
   33    51      > FE_RESET_R                                           $27     !2, ->59
         52    > > FE_FETCH_R                                                   $27, !3, ->59
   34    53    >   FETCH_OBJ_R                                          ~28     !3, 'textContent'
         54        FRAMELESS_ICALL_1                trim                ~29     ~28
         55        CONCAT                                               ~30     '+%2A+', ~29
         56        CONCAT                                               ~31     ~30, '%0A'
         57        ECHO                                                         ~31
   33    58      > JMP                                                          ->52
         59    >   FE_FREE                                                      $27
   36    60        ECHO                                                         '%0A'
   37    61        ECHO                                                         'DOM+serialised%3A%0A'
   38    62        INIT_METHOD_CALL                                             !4, 'saveHtml'
         63        DO_FCALL                                          0  $32     
         64        ECHO                                                         $32
         65      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
153.98 ms | 1338 KiB | 13 Q