How would I go about removing script tags, and everything inside them using PHP?
Note that HTML attribute values may contain plain `>` characters.
Gumbo
2010-04-23 11:26:47
+4
A:
As David says, filtering only script tags is not enough if you're looking to sanitize incoming data. HTML Purifier promises to do the full package:
HTML Purifier is a standards-compliant HTML filter library written in PHP. HTML Purifier will not only remove all malicious code (better known as XSS) with a thoroughly audited, secure yet permissive whitelist, it will also make sure your documents are standards compliant, something only achievable with a comprehensive knowledge of W3C's specifications.
Pekka
2010-04-23 11:26:00
+2
A:
Go with HTML Purifier as Pekka suggested.
Never go with regex for that case
Here is a example, regexes filters broken, works on browsers (tested on firefox)
<script script=">>><script></script><script>//" >
/**/
alert(1);
</script
>
S.Mark
2010-04-23 11:33:14
A:
You can do that with the function strip_tags
<?php
$text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>';
echo strip_tags($text);
// Allow <p> and <a>
echo strip_tags($text, '<p><a>');
?>
Marco
2010-04-23 14:10:30