3v4l.org

run code in 300+ PHP versions simultaneously
<?php function remove_script_tags($html){ $dom = new DOMDocument(); $dom->loadHTML($html); $script = $dom->getElementsByTagName('script'); $remove = []; foreach($script as $item){ $remove[] = $item; } foreach ($remove as $item){ $item->parentNode->removeChild($item); } $html = $dom->saveHTML(); return $html; } $s = []; $s[] = "hey buddy what's up script"; $s[] = "Hi Friend <script>alert('hello world');</script>"; $s[] = "<script src=\"http://jquery.com\">joyjoy</script>happy"; foreach($s as $t){ echo $t.' ==> '.remove_script_tags($t)."\n"; }
Output for 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.29, 8.2.0 - 8.2.21, 8.3.0 - 8.3.9
hey buddy what's up script ==> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><body><p>hey buddy what's up script</p></body></html> Hi Friend <script>alert('hello world');</script> ==> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><body><p>Hi Friend </p></body></html> <script src="http://jquery.com">joyjoy</script>happy ==> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><head></head><body><p>happy</p></body></html>

preferences:
156.89 ms | 404 KiB | 183 Q