3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = "<p>Hello World</p> <div class='sometestclass'> <img src='foo.png'/> <div>Bar</div> </div>"; $clean = removeDiv ($html,'sometestclass'); echo $clean; function removeDiv ($html,$removeClass){ $dom = new DOMDocument; $dom->loadHTML( $html ); $xpath = new DOMXPath( $dom ); $removeString = ".//div[@class=$removeClass]"; $pDivs = $xpath->query($removeString); foreach ( $pDivs as $div ) { $div->parentNode->removeChild( $div ); } $output = preg_replace( "/.*<body>(.*)<\/body>.*/s", "$1", $dom->saveHTML() ); echo $output; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3QvUd
function name:  (null)
number of ops:  8
compiled vars:  !0 = $html, !1 = $clean
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Cp%3EHello+World%3C%2Fp%3E%0A+++++++++%3Cdiv+class%3D%27sometestclass%27%3E%0A+++++++++++%3Cimg+src%3D%27foo.png%27%2F%3E%0A+++++++++++%3Cdiv%3EBar%3C%2Fdiv%3E%0A+++++++++%3C%2Fdiv%3E'
    8     1        INIT_FCALL_BY_NAME                                       'removeDiv'
          2        SEND_VAR_EX                                              !0
          3        SEND_VAL_EX                                              'sometestclass'
          4        DO_FCALL                                      0  $3      
          5        ASSIGN                                                   !1, $3
    9     6        ECHO                                                     !1
   25     7      > RETURN                                                   1

Function removediv:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 27
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 27
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/3QvUd
function name:  removeDiv
number of ops:  38
compiled vars:  !0 = $html, !1 = $removeClass, !2 = $dom, !3 = $xpath, !4 = $removeString, !5 = $pDivs, !6 = $div, !7 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   12     2        NEW                                              $8      'DOMDocument'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !2, $8
   13     5        INIT_METHOD_CALL                                         !2, 'loadHTML'
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0          
   15     8        NEW                                              $12     'DOMXPath'
          9        SEND_VAR_EX                                              !2
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !3, $12
   16    12        ROPE_INIT                                     3  ~16     '.%2F%2Fdiv%5B%40class%3D'
         13        ROPE_ADD                                      1  ~16     ~16, !1
         14        ROPE_END                                      2  ~15     ~16, '%5D'
         15        ASSIGN                                                   !4, ~15
   17    16        INIT_METHOD_CALL                                         !3, 'query'
         17        SEND_VAR_EX                                              !4
         18        DO_FCALL                                      0  $19     
         19        ASSIGN                                                   !5, $19
   19    20      > FE_RESET_R                                       $21     !5, ->27
         21    > > FE_FETCH_R                                               $21, !6, ->27
   20    22    >   FETCH_OBJ_R                                      ~22     !6, 'parentNode'
         23        INIT_METHOD_CALL                                         ~22, 'removeChild'
         24        SEND_VAR_EX                                              !6
         25        DO_FCALL                                      0          
   19    26      > JMP                                                      ->21
         27    >   FE_FREE                                                  $21
   23    28        INIT_FCALL                                               'preg_replace'
         29        SEND_VAL                                                 '%2F.%2A%3Cbody%3E%28.%2A%29%3C%5C%2Fbody%3E.%2A%2Fs'
         30        SEND_VAL                                                 '%241'
         31        INIT_METHOD_CALL                                         !2, 'saveHTML'
         32        DO_FCALL                                      0  $24     
         33        SEND_VAR                                                 $24
         34        DO_ICALL                                         $25     
         35        ASSIGN                                                   !7, $25
   24    36        ECHO                                                     !7
   25    37      > RETURN                                                   null

End of function removediv

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.4 ms | 1400 KiB | 15 Q