3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<EOD <h1>Escape HTML or Other Programming tags</h1> <p>This must be rendered without any problem</p> <p> <code style="display:block;background:rgb(230,230,230);padding:2%"> <h4>Show this title in HTML</h4> <p>This paragraph must be in <strong>HTML</strong> and this <a href="">Link</a> too !</p> <?php echo "Display this PHP code!"; ?> <script> alert("Don't pop-up please!"); </script> </code> <a href="">Link rendered</a> </p> EOD; $dom = new DOMDocument; $dom->loadHTML($html); $xpath = new DOMXPath($dom); $preformattedCodeNode = $dom->createElement('pre'); foreach ($xpath->query("//code") as $codeNode) { $codeContent = ''; foreach($codeNode->childNodes as $codeChild) { $codeContent .= $dom->saveHTML($codeChild); } $preformattedCodeNode->textContent = $codeContent; $preformattedCodeNode->setAttribute('style', $codeNode->getAttribute('style')); $codeNode->parentNode->replaceChild($preformattedCodeNode, $codeNode); } $texte = $dom->saveHTML(); echo $texte;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 19, Position 2 = 45
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 45
Branch analysis from position: 20
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 29
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 29
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 29
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
filename:       /in/rYBPq
function name:  (null)
number of ops:  51
compiled vars:  !0 = $html, !1 = $dom, !2 = $xpath, !3 = $preformattedCodeNode, !4 = $codeNode, !5 = $codeContent, !6 = $codeChild, !7 = $texte
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '++++%3Ch1%3EEscape+HTML+or+Other+Programming+tags%3C%2Fh1%3E%0A++++%3Cp%3EThis+must+be+rendered+without+any+problem%3C%2Fp%3E%0A++++%3Cp%3E%0A++++%3Ccode+style%3D%22display%3Ablock%3Bbackground%3Argb%28230%2C230%2C230%29%3Bpadding%3A2%25%22%3E%0A++++++++%3Ch4%3EShow+this+title+in+HTML%3C%2Fh4%3E%0A++++++++%3Cp%3EThis+paragraph+must+be+in+%3Cstrong%3EHTML%3C%2Fstrong%3E+and+this+%3Ca+href%3D%22%22%3ELink%3C%2Fa%3E+too+%21%3C%2Fp%3E%0A++++++++%3C%3Fphp+%0A++++++++++++echo+%22Display+this+PHP+code%21%22%3B%0A++++++++%3F%3E%0A++++++++%3Cscript%3E%0A++++++++++++alert%28%22Don%27t+pop-up+please%21%22%29%3B%0A++++++++%3C%2Fscript%3E%0A++++%3C%2Fcode%3E%0A++++%3Ca+href%3D%22%22%3ELink+rendered%3C%2Fa%3E%0A++++%3C%2Fp%3E+'
   21     1        NEW                                              $9      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $9
   22     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   23     7        NEW                                              $13     'DOMXPath'
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !2, $13
   24    11        INIT_METHOD_CALL                                         !1, 'createElement'
         12        SEND_VAL_EX                                              'pre'
         13        DO_FCALL                                      0  $16     
         14        ASSIGN                                                   !3, $16
   26    15        INIT_METHOD_CALL                                         !2, 'query'
         16        SEND_VAL_EX                                              '%2F%2Fcode'
         17        DO_FCALL                                      0  $18     
         18      > FE_RESET_R                                       $19     $18, ->45
         19    > > FE_FETCH_R                                               $19, !4, ->45
   27    20    >   ASSIGN                                                   !5, ''
   29    21        FETCH_OBJ_R                                      ~21     !4, 'childNodes'
         22      > FE_RESET_R                                       $22     ~21, ->29
         23    > > FE_FETCH_R                                               $22, !6, ->29
   30    24    >   INIT_METHOD_CALL                                         !1, 'saveHTML'
         25        SEND_VAR_EX                                              !6
         26        DO_FCALL                                      0  $23     
         27        ASSIGN_OP                                     8          !5, $23
   29    28      > JMP                                                      ->23
         29    >   FE_FREE                                                  $22
   33    30        ASSIGN_OBJ                                               !3, 'textContent'
         31        OP_DATA                                                  !5
   34    32        INIT_METHOD_CALL                                         !3, 'setAttribute'
         33        SEND_VAL_EX                                              'style'
         34        INIT_METHOD_CALL                                         !4, 'getAttribute'
         35        SEND_VAL_EX                                              'style'
         36        DO_FCALL                                      0  $26     
         37        SEND_VAR_NO_REF_EX                                       $26
         38        DO_FCALL                                      0          
   36    39        FETCH_OBJ_R                                      ~28     !4, 'parentNode'
         40        INIT_METHOD_CALL                                         ~28, 'replaceChild'
         41        SEND_VAR_EX                                              !3
         42        SEND_VAR_EX                                              !4
         43        DO_FCALL                                      0          
   26    44      > JMP                                                      ->19
         45    >   FE_FREE                                                  $19
   39    46        INIT_METHOD_CALL                                         !1, 'saveHTML'
         47        DO_FCALL                                      0  $30     
         48        ASSIGN                                                   !7, $30
   40    49        ECHO                                                     !7
   41    50      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167 ms | 1399 KiB | 13 Q