Snippet Name: Censor Message Text
Description: Fill the "$bw" string with bad words separated by a pipe symbol and then run your text through it.
Also see: » Vulnerability Tester
» Block IP Addresses
» Ban Proxy Servers
» Bad Word Filter
» Anti-Flood Protection
» Anti-SQL Injection Function
» XSS Sanitizer Function
» Filter non-alphanumeric characters
Comment: (none)
Language: PHP
Highlight Mode: PHP
Last Modified: March 16th, 2009
|
<?PHP
$bw = "words|seperated|by|pipe|symbols";
FUNCTION str_repeats($input, $mult) {
$ret = "";
WHILE($mult>0) {
$ret .= $input;
$mult --;
}
RETURN $ret;
}
FUNCTION censorMsg($msg, $replacement="*") {
GLOBAL $bw;
$badwords = EXPLODE("|", $bw);
$eachword = EXPLODE(" ", $msg);
FOR($j=0;$j<count($badwords);$j++) {
FOR($i=0;$i<count($eachword);$i++) {
IF(IS_INT(STRPOS(STRTOLOWER($eachword[$i]), $badwords[$j]))) {
$msg = EREGI_REPLACE($eachword[$i],
str_repeats($replacement,
STRLEN($eachword[$i])),
STRIPSLASHES($msg));
}
}
}
RETURN $msg;
}
$msg = $_POST["msg"];
IF (ISSET($msg)) {
$msg = censorMsg($msg,"*");
PRINT "Your posted Message :<br>".$msg;
}
?>
<form method="post">
<textarea name="msg" cols=50 rows=10></txtarea><br>
<input type="submit" value="Censor It">
</form>
|