3v4l.org

run code in 300+ PHP versions simultaneously
<?php function wrap_js($js) { $confirm_text = "It will not be possible to modify your responses anymore if you continue.\\n\\nAre you sure you want to continue?"; $new_js_start = 'if( window.confirm("' . $confirm_text . '") ) { '; $new_js_end = ' } else { event.preventDefault(); }'; return $new_js_start . $js . $new_js_end; } $html = "<input type='submit' id='gform_submit_button_4' class='gform_button button' value='Envoyer' onclick='/* Lots of JS */' onkeypress='/* Lots of JS */' />"; $doc = new DOMDocument(); $doc->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $xpath = new DOMXPath($doc); foreach ($xpath->query("//input[@type='submit']") as $submit_input) { foreach (['onclick', 'onkeypress'] as $attribute) { if (($js = $submit_input->getAttribute($attribute)) != '') { $submit_input->setAttribute($attribute, wrap_js($js)); } } } echo $doc->saveHTML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 35
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 35
Branch analysis from position: 17
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 33
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 33
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 32
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 32
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 33
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
filename:       /in/DncpM
function name:  (null)
number of ops:  40
compiled vars:  !0 = $html, !1 = $doc, !2 = $xpath, !3 = $submit_input, !4 = $attribute, !5 = $js
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   ASSIGN                                                   !0, '%3Cinput+type%3D%27submit%27+id%3D%27gform_submit_button_4%27+class%3D%27gform_button+button%27+value%3D%27Envoyer%27++onclick%3D%27%2F%2A+Lots+of+JS+%2A%2F%27+onkeypress%3D%27%2F%2A+Lots+of+JS+%2A%2F%27+%2F%3E'
    9     1        NEW                                              $7      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $7
   10     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        SEND_VAL_EX                                              8196
          7        DO_FCALL                                      0          
   11     8        NEW                                              $11     'DOMXPath'
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !2, $11
   12    12        INIT_METHOD_CALL                                         !2, 'query'
         13        SEND_VAL_EX                                              '%2F%2Finput%5B%40type%3D%27submit%27%5D'
         14        DO_FCALL                                      0  $14     
         15      > FE_RESET_R                                       $15     $14, ->35
         16    > > FE_FETCH_R                                               $15, !3, ->35
   13    17    > > FE_RESET_R                                       $16     <array>, ->33
         18    > > FE_FETCH_R                                               $16, !4, ->33
   14    19    >   INIT_METHOD_CALL                                         !3, 'getAttribute'
         20        SEND_VAR_EX                                              !4
         21        DO_FCALL                                      0  $17     
         22        ASSIGN                                           ~18     !5, $17
         23        IS_NOT_EQUAL                                             ~18, ''
         24      > JMPZ                                                     ~19, ->32
   15    25    >   INIT_METHOD_CALL                                         !3, 'setAttribute'
         26        SEND_VAR_EX                                              !4
         27        INIT_FCALL                                               'wrap_js'
         28        SEND_VAR                                                 !5
         29        DO_FCALL                                      0  $20     
         30        SEND_VAR_NO_REF_EX                                       $20
         31        DO_FCALL                                      0          
   13    32    > > JMP                                                      ->18
         33    >   FE_FREE                                                  $16
   12    34      > JMP                                                      ->16
         35    >   FE_FREE                                                  $15
   19    36        INIT_METHOD_CALL                                         !1, 'saveHTML'
         37        DO_FCALL                                      0  $22     
         38        ECHO                                                     $22
         39      > RETURN                                                   1

Function wrap_js:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DncpM
function name:  wrap_js
number of ops:  10
compiled vars:  !0 = $js, !1 = $confirm_text, !2 = $new_js_start, !3 = $new_js_end
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        ASSIGN                                                   !1, 'It+will+not+be+possible+to+modify+your+responses+anymore+if+you+continue.%5Cn%5CnAre+you+sure+you+want+to+continue%3F'
    4     2        CONCAT                                           ~5      'if%28+window.confirm%28%22', !1
          3        CONCAT                                           ~6      ~5, '%22%29+%29+%7B+'
          4        ASSIGN                                                   !2, ~6
    5     5        ASSIGN                                                   !3, '+%7D+else+%7B+event.preventDefault%28%29%3B+%7D'
    6     6        CONCAT                                           ~9      !2, !0
          7        CONCAT                                           ~10     ~9, !3
          8      > RETURN                                                   ~10
    7     9*     > RETURN                                                   null

End of function wrap_js

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.4 ms | 1011 KiB | 14 Q