3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <script id="tmpl-theme" type="text/template"> <# if ( data.screenshot[0] ) { #> <div class="theme-screenshot"> <img src="{{ data.screenshot[0] }}" alt="" /> </div> <# } else { #> <div class="theme-screenshot blank"></div> <# } #> <# if ( data.hasUpdate ) { #> <# if ( data.hasPackage ) { #> <div class="update-message notice inline notice-warning notice-alt"><p>New version available. <button class="button-link" type="button">Update now</button></p></div> <# } else { #> <div class="update-message notice inline notice-warning notice-alt"><p>New version available.</p></div> <# } #> <# } #> <span class="more-details" id="{{ data.id }}-action">Theme Details</span> <div class="theme-author"> By {{{ data.author }}} </div> <# if ( data.active ) { #> <h2 class="theme-name" id="{{ data.id }}-name"> <span>Active:</span> {{{ data.name }}} </h2> <# } else { #> <h2 class="theme-name" id="{{ data.id }}-name">{{{ data.name }}}</h2> <# } #> <div class="theme-actions"> <# if ( data.active ) { #> <# if ( data.actions.customize ) { #> <a class="button button-primary customize load-customize hide-if-no-customize" href="%7B%7B%7B%20data.actions.customize%20%7D%7D%7D">Customize</a> <# } #> <# } else { #> <a class="button activate" href="%7B%7B%7B%20data.actions.activate%20%7D%7D%7D" aria-label="Activate {{ data.name }}">Activate</a> <a class="button button-primary load-customize hide-if-no-customize" href="%7B%7B%7B%20data.actions.customize%20%7D%7D%7D">Live Preview</a> <# } #> </div> </script> HTML; function remove_scripts($html) { $scripts = []; $i = 0; $template = '___REPLACED_SCRIPT_%d___'; preg_replace_callback('#<script.+?</script>#is', function($match) use($html, $template, &$scripts, &$i) { do { $replacement = sprintf($template, $i++); } while (strpos($html, $replacement) !== false); $scripts[$replacement] = $match[0]; return $replacement; }, $html); return [$html, $scripts]; } var_dump(remove_scripts($html));
Output for 7.1.2, 7.3.24 - 7.3.33, 7.4.12 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
array(2) { [0]=> string(1566) "<script id="tmpl-theme" type="text/template"> <# if ( data.screenshot[0] ) { #> <div class="theme-screenshot"> <img src="{{ data.screenshot[0] }}" alt="" /> </div> <# } else { #> <div class="theme-screenshot blank"></div> <# } #> <# if ( data.hasUpdate ) { #> <# if ( data.hasPackage ) { #> <div class="update-message notice inline notice-warning notice-alt"><p>New version available. <button class="button-link" type="button">Update now</button></p></div> <# } else { #> <div class="update-message notice inline notice-warning notice-alt"><p>New version available.</p></div> <# } #> <# } #> <span class="more-details" id="{{ data.id }}-action">Theme Details</span> <div class="theme-author"> By {{{ data.author }}} </div> <# if ( data.active ) { #> <h2 class="theme-name" id="{{ data.id }}-name"> <span>Active:</span> {{{ data.name }}} </h2> <# } else { #> <h2 class="theme-name" id="{{ data.id }}-name">{{{ data.name }}}</h2> <# } #> <div class="theme-actions"> <# if ( data.active ) { #> <# if ( data.actions.customize ) { #> <a class="button button-primary customize load-customize hide-if-no-customize" href="%7B%7B%7B%20data.actions.customize%20%7D%7D%7D">Customize</a> <# } #> <# } else { #> <a class="button activate" href="%7B%7B%7B%20data.actions.activate%20%7D%7D%7D" aria-label="Activate {{ data.name }}">Activate</a> <a class="button button-primary load-customize hide-if-no-customize" href="%7B%7B%7B%20data.actions.customize%20%7D%7D%7D">Live Preview</a> <# } #> </div> </script>" [1]=> array(1) { ["___REPLACED_SCRIPT_0___"]=> string(1566) "<script id="tmpl-theme" type="text/template"> <# if ( data.screenshot[0] ) { #> <div class="theme-screenshot"> <img src="{{ data.screenshot[0] }}" alt="" /> </div> <# } else { #> <div class="theme-screenshot blank"></div> <# } #> <# if ( data.hasUpdate ) { #> <# if ( data.hasPackage ) { #> <div class="update-message notice inline notice-warning notice-alt"><p>New version available. <button class="button-link" type="button">Update now</button></p></div> <# } else { #> <div class="update-message notice inline notice-warning notice-alt"><p>New version available.</p></div> <# } #> <# } #> <span class="more-details" id="{{ data.id }}-action">Theme Details</span> <div class="theme-author"> By {{{ data.author }}} </div> <# if ( data.active ) { #> <h2 class="theme-name" id="{{ data.id }}-name"> <span>Active:</span> {{{ data.name }}} </h2> <# } else { #> <h2 class="theme-name" id="{{ data.id }}-name">{{{ data.name }}}</h2> <# } #> <div class="theme-actions"> <# if ( data.active ) { #> <# if ( data.actions.customize ) { #> <a class="button button-primary customize load-customize hide-if-no-customize" href="%7B%7B%7B%20data.actions.customize%20%7D%7D%7D">Customize</a> <# } #> <# } else { #> <a class="button activate" href="%7B%7B%7B%20data.actions.activate%20%7D%7D%7D" aria-label="Activate {{ data.name }}">Activate</a> <a class="button button-primary load-customize hide-if-no-customize" href="%7B%7B%7B%20data.actions.customize%20%7D%7D%7D">Live Preview</a> <# } #> </div> </script>" } }

preferences:
202.42 ms | 1952 KiB | 4 Q