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();
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
<input type="submit" id="gform_submit_button_4" class="gform_button button" value="Envoyer" onclick='if( window.confirm("It will not be possible to modify your responses anymore if you continue.\n\nAre you sure you want to continue?") ) { /* Lots of JS */ } else { event.preventDefault(); }' onkeypress='if( window.confirm("It will not be possible to modify your responses anymore if you continue.\n\nAre you sure you want to continue?") ) { /* Lots of JS */ } else { event.preventDefault(); }'>

preferences:
157.25 ms | 409 KiB | 5 Q