3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <body> <div>foo</div> <shortcode type="content" /> <div>bar</div> </body> HTML; $replace = <<<HTML <div>content</div> HTML; $dom = new DOMDocument(); libxml_use_internal_errors(true); $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); echo $dom->saveHTML($dom->documentElement); echo PHP_EOL, '---------------------------', PHP_EOL; $xpath = new DOMXPath($dom); $nodes = $xpath->query('//shortcode'); foreach($nodes as $node) { $newHTML = $dom->createDocumentFragment(); $newHTML->appendXML($replace); $node->parentNode->insertBefore($newHTML, $node); $node->parentNode->removeChild($node); } echo $dom->saveHTML($dom->documentElement);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 30, Position 2 = 47
Branch analysis from position: 30
2 jumps found. (Code = 78) Position 1 = 31, Position 2 = 47
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
filename:       /in/ufi21
function name:  (null)
number of ops:  55
compiled vars:  !0 = $html, !1 = $replace, !2 = $dom, !3 = $xpath, !4 = $nodes, !5 = $node, !6 = $newHTML
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Cbody%3E%0A%09%3Cdiv%3Efoo%3C%2Fdiv%3E%0A%09%3Cshortcode+type%3D%22content%22+%2F%3E%0A%09%3Cdiv%3Ebar%3C%2Fdiv%3E%0A%3C%2Fbody%3E'
   11     1        ASSIGN                                                   !1, '%09%3Cdiv%3Econtent%3C%2Fdiv%3E'
   16     2        NEW                                              $9      'DOMDocument'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !2, $9
   17     5        INIT_FCALL                                               'libxml_use_internal_errors'
          6        SEND_VAL                                                 <true>
          7        DO_ICALL                                                 
   18     8        INIT_METHOD_CALL                                         !2, 'loadHTML'
          9        SEND_VAR_EX                                              !0
         10        SEND_VAL_EX                                              8196
         11        DO_FCALL                                      0          
   20    12        INIT_METHOD_CALL                                         !2, 'saveHTML'
         13        CHECK_FUNC_ARG                                           
         14        FETCH_OBJ_FUNC_ARG                               $14     !2, 'documentElement'
         15        SEND_FUNC_ARG                                            $14
         16        DO_FCALL                                      0  $15     
         17        ECHO                                                     $15
   21    18        ECHO                                                     '%0A'
         19        ECHO                                                     '---------------------------'
         20        ECHO                                                     '%0A'
   23    21        NEW                                              $16     'DOMXPath'
         22        SEND_VAR_EX                                              !2
         23        DO_FCALL                                      0          
         24        ASSIGN                                                   !3, $16
   24    25        INIT_METHOD_CALL                                         !3, 'query'
         26        SEND_VAL_EX                                              '%2F%2Fshortcode'
         27        DO_FCALL                                      0  $19     
         28        ASSIGN                                                   !4, $19
   25    29      > FE_RESET_R                                       $21     !4, ->47
         30    > > FE_FETCH_R                                               $21, !5, ->47
   26    31    >   INIT_METHOD_CALL                                         !2, 'createDocumentFragment'
         32        DO_FCALL                                      0  $22     
         33        ASSIGN                                                   !6, $22
   27    34        INIT_METHOD_CALL                                         !6, 'appendXML'
         35        SEND_VAR_EX                                              !1
         36        DO_FCALL                                      0          
   28    37        FETCH_OBJ_R                                      ~25     !5, 'parentNode'
         38        INIT_METHOD_CALL                                         ~25, 'insertBefore'
         39        SEND_VAR_EX                                              !6
         40        SEND_VAR_EX                                              !5
         41        DO_FCALL                                      0          
   29    42        FETCH_OBJ_R                                      ~27     !5, 'parentNode'
         43        INIT_METHOD_CALL                                         ~27, 'removeChild'
         44        SEND_VAR_EX                                              !5
         45        DO_FCALL                                      0          
   25    46      > JMP                                                      ->30
         47    >   FE_FREE                                                  $21
   31    48        INIT_METHOD_CALL                                         !2, 'saveHTML'
         49        CHECK_FUNC_ARG                                           
         50        FETCH_OBJ_FUNC_ARG                               $29     !2, 'documentElement'
         51        SEND_FUNC_ARG                                            $29
         52        DO_FCALL                                      0  $30     
         53        ECHO                                                     $30
         54      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
178.19 ms | 1400 KiB | 15 Q