3v4l.org

run code in 300+ PHP versions simultaneously
<?php function load($html) { $document = <<<EOD <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head> <body>!html</body> </html> EOD; // PHP's \DOMDocument::saveXML() encodes carriage returns as &#13; so // normalize all newlines to line feeds. $html = str_replace(["\r\n", "\r"], "\n", $html); // PHP's \DOMDocument serialization adds extra whitespace when the markup // of the wrapping document contains newlines, so ensure we remove all // newlines before injecting the actual HTML body to be processed. $document = strtr($document, ["\n" => '', '!html' => $html]); $dom = new \DOMDocument(); // Ignore warnings during HTML soup loading. @$dom->loadHTML($document, LIBXML_NOBLANKS); return $dom; } function _serialize(\DOMDocument $document) { $body_node = $document->getElementsByTagName('body')->item(0); $html = ''; if ($body_node !== NULL) { foreach ($body_node->childNodes as $node) { $html .= $document->saveXML($node); } } return $html; } print _serialize(load('<a class="sample" href="http://www.example.com/partial/path">foo</a>')); print PHP_EOL; print _serialize(load('<a class="sample" href="http://www.example.com/partial/path'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/r6nNq
function name:  (null)
number of ops:  16
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   INIT_FCALL                                               '_serialize'
          1        INIT_FCALL                                               'load'
          2        SEND_VAL                                                 '%3Ca+class%3D%22sample%22+href%3D%22http%3A%2F%2Fwww.example.com%2Fpartial%2Fpath%22%3Efoo%3C%2Fa%3E'
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_FCALL                                      0  $1      
          6        ECHO                                                     $1
   43     7        ECHO                                                     '%0A'
   44     8        INIT_FCALL                                               '_serialize'
          9        INIT_FCALL                                               'load'
         10        SEND_VAL                                                 '%3Ca+class%3D%22sample%22+href%3D%22http%3A%2F%2Fwww.example.com%2Fpartial%2Fpath'
         11        DO_FCALL                                      0  $2      
         12        SEND_VAR                                                 $2
         13        DO_FCALL                                      0  $3      
         14        ECHO                                                     $3
         15      > RETURN                                                   1

Function load:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/r6nNq
function name:  load
number of ops:  26
compiled vars:  !0 = $html, !1 = $document, !2 = $dom
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, '++++%3C%21DOCTYPE+html+PUBLIC+%22-%2F%2FW3C%2F%2FDTD+XHTML+1.0+Strict%2F%2FEN%22+%22http%3A%2F%2Fwww.w3.org%2FTR%2Fxhtml1%2FDTD%2Fxhtml1-strict.dtd%22%3E%0A++++%3Chtml+xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%0A++++%3Chead%3E%3Cmeta+http-equiv%3D%22Content-Type%22+content%3D%22text%2Fhtml%3B+charset%3Dutf-8%22+%2F%3E%3C%2Fhead%3E%0A++++%3Cbody%3E%21html%3C%2Fbody%3E%0A++++%3C%2Fhtml%3E'
   14     2        INIT_FCALL                                               'str_replace'
          3        SEND_VAL                                                 <array>
          4        SEND_VAL                                                 '%0A'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $4      
          7        ASSIGN                                                   !0, $4
   19     8        INIT_FCALL                                               'strtr'
          9        SEND_VAR                                                 !1
         10        INIT_ARRAY                                       ~6      '', '%0A'
         11        ADD_ARRAY_ELEMENT                                ~6      !0, '%21html'
         12        SEND_VAL                                                 ~6
         13        DO_ICALL                                         $7      
         14        ASSIGN                                                   !1, $7
   21    15        NEW                                              $9      'DOMDocument'
         16        DO_FCALL                                      0          
         17        ASSIGN                                                   !2, $9
   23    18        BEGIN_SILENCE                                    ~12     
         19        INIT_METHOD_CALL                                         !2, 'loadHTML'
         20        SEND_VAR_EX                                              !1
         21        SEND_VAL_EX                                              256
         22        DO_FCALL                                      0          
         23        END_SILENCE                                              ~12
   24    24      > RETURN                                                   !2
   25    25*     > RETURN                                                   null

End of function load

Function _serialize:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 20
Branch analysis from position: 11
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 19
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 19
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
Branch analysis from position: 20
filename:       /in/r6nNq
function name:  _serialize
number of ops:  22
compiled vars:  !0 = $document, !1 = $body_node, !2 = $html, !3 = $node
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   28     1        INIT_METHOD_CALL                                         !0, 'getElementsByTagName'
          2        SEND_VAL_EX                                              'body'
          3        DO_FCALL                                      0  $4      
          4        INIT_METHOD_CALL                                         $4, 'item'
          5        SEND_VAL_EX                                              0
          6        DO_FCALL                                      0  $5      
          7        ASSIGN                                                   !1, $5
   29     8        ASSIGN                                                   !2, ''
   31     9        TYPE_CHECK                                  1020          !1
         10      > JMPZ                                                     ~8, ->20
   32    11    >   FETCH_OBJ_R                                      ~9      !1, 'childNodes'
         12      > FE_RESET_R                                       $10     ~9, ->19
         13    > > FE_FETCH_R                                               $10, !3, ->19
   33    14    >   INIT_METHOD_CALL                                         !0, 'saveXML'
         15        SEND_VAR_EX                                              !3
         16        DO_FCALL                                      0  $11     
         17        ASSIGN_OP                                     8          !2, $11
   32    18      > JMP                                                      ->13
         19    >   FE_FREE                                                  $10
   36    20    > > RETURN                                                   !2
   37    21*     > RETURN                                                   null

End of function _serialize

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.33 ms | 1467 KiB | 19 Q