[thelist] Tip: Bad Word Censoring Function
David Bindel
dbindel at austin.rr.com
Fri Aug 23 20:08:01 CDT 2002
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
<tip type="Bad Word Censoring" author="David Bindel">
Here is a function that will censor bad words in a string you pass to it.
For example, if you pass "bitch" to it, it returns "b----". It is written
in PHP, but should be pretty simple to convert to any other language.
<?php
function censor($text) {
$mask = "-";
$badwords = array("bitch", "bastard", "fuck");
for ($i = 0; $i < sizeof($words); $i++) {
$censored = substr($badwords[$i], 0, 1);
for ($x = 1; $x < strlen($badwords[$i]); $x++) $censored .= $mask;
$text = str_replace($badwords[$i], $censored, $text);
}
return $text;
}
?>
You can easily change the mask character ("-" by default) to any other
character you wish (for example, "*"). The list of bad words is expandable
to any size, and don't think that these are the only bad words I know, I
just left the rest out for readability purposes.
HTH!
David Bindel
</tip>
-----BEGIN PGP SIGNATURE-----
Version: PGP 7.0.4
iQA/AwUBPWbcWbwc2umqeOxSEQJA6wCeOIhxWfuyZXupHW5QntcrTMAmtBYAoK+l
jEjxGKhevHXhB1pknef9R1GE
=P3dK
-----END PGP SIGNATURE-----
More information about the thelist
mailing list