3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); $html = <<<HTML <form method="post" class="form" data-id="19" data-title="Schema" data-slug="schema" data-message-success="Success!" data-message-invalid-email="Not valid!" data-message-required-field-missing="All fields are required!" data-message-error="Error!"> --- Form content --- <div>with some tags</div> </form> HTML; $doc = new DOMDocument('1.0', 'UTF-8'); $doc->loadHTML($html); $xpath = new DOMXPath($doc); foreach ($xpath->query('//form') as $formTag) { // remove child nodes of the form tag foreach ([...$formTag->childNodes] as $child) { $formTag->removeChild($child); } // output as string, but remove the closing tag echo substr($doc->saveHTML($formTag), 0, -7); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 38
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 38
Branch analysis from position: 18
2 jumps found. (Code = 77) Position 1 = 22, Position 2 = 27
Branch analysis from position: 22
2 jumps found. (Code = 78) Position 1 = 23, Position 2 = 27
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 27
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
filename:       /in/QS34g
function name:  (null)
number of ops:  40
compiled vars:  !0 = $html, !1 = $doc, !2 = $xpath, !3 = $formTag, !4 = $child
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, '%3Cform+method%3D%22post%22+class%3D%22form%22+data-id%3D%2219%22+data-title%3D%22Schema%22+data-slug%3D%22schema%22+data-message-success%3D%22Success%21%22+data-message-invalid-email%3D%22Not+valid%21%22+data-message-required-field-missing%3D%22All+fields+are+required%21%22+data-message-error%3D%22Error%21%22%3E%0A++++---+Form+content+---%0A++++%3Cdiv%3Ewith+some+tags%3C%2Fdiv%3E%0A%3C%2Fform%3E'
   11     1        NEW                                              $6      'DOMDocument'
          2        SEND_VAL_EX                                              '1.0'
          3        SEND_VAL_EX                                              'UTF-8'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $6
   12     6        INIT_METHOD_CALL                                         !1, 'loadHTML'
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0          
   14     9        NEW                                              $10     'DOMXPath'
         10        SEND_VAR_EX                                              !1
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !2, $10
   16    13        INIT_METHOD_CALL                                         !2, 'query'
         14        SEND_VAL_EX                                              '%2F%2Fform'
         15        DO_FCALL                                      0  $13     
         16      > FE_RESET_R                                       $14     $13, ->38
         17    > > FE_FETCH_R                                               $14, !3, ->38
   18    18    >   FETCH_OBJ_R                                      ~15     !3, 'childNodes'
         19        INIT_ARRAY                                       ~16     
         20        ADD_ARRAY_UNPACK                                 ~16     ~15
         21      > FE_RESET_R                                       $17     ~16, ->27
         22    > > FE_FETCH_R                                               $17, !4, ->27
   19    23    >   INIT_METHOD_CALL                                         !3, 'removeChild'
         24        SEND_VAR_EX                                              !4
         25        DO_FCALL                                      0          
   18    26      > JMP                                                      ->22
         27    >   FE_FREE                                                  $17
   23    28        INIT_FCALL                                               'substr'
         29        INIT_METHOD_CALL                                         !1, 'saveHTML'
         30        SEND_VAR_EX                                              !3
         31        DO_FCALL                                      0  $19     
         32        SEND_VAR                                                 $19
         33        SEND_VAL                                                 0
         34        SEND_VAL                                                 -7
         35        DO_ICALL                                         $20     
         36        ECHO                                                     $20
   16    37      > JMP                                                      ->17
         38    >   FE_FREE                                                  $14
   24    39      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.7 ms | 1015 KiB | 14 Q