Best method of taking out bad words and replacing them with their first letter and the rest of the letters are changed to *'s
i.e. S***, F***, A******
<Sorry if this is going to be moved to regex, i didn't know which thread to put it in...>
Bad word filter
Moderator: General Moderators
yeah, regex. ^_^
Lesse...
Should work. 
Lesse...
Code: Select all
$badwords = array(
'/(happy)/ie',
'/(rainbow)/ie',
'/(fun)/ie',
#etc
);
$text = preg_replace($badwords,'filter("\\1")',$text);
function filter($text) {
$stars = '';
for ($i=1; $i < strlen($text); $i++) {
$stars .= '*';
}
return $text[0].$stars;
}Code: Select all
$badwords = "/(happy|rainbow|fun)/ie";
$text = preg_replace($badwords,'filter("\\1")',$text);
function filter ( $text ) {
for ($i=1; $i < strlen($text); $i++)
$stars .= '*';
return $text[0].$stars;
}if your looking for a list neophyte kindly gave a link to a mysql file full of them. You will have to strip the mysql commands from around it but it might be easier then writing your own list from scratch.
viewtopic.php?t=33384&highlight=word+censor
viewtopic.php?t=33384&highlight=word+censor
I don't need that extensive of a list, but thanks for the reference!
Slight adjustment - I didn't like that it was taking the middle of words out... for example.... bass... so...
Slight adjustment - I didn't like that it was taking the middle of words out... for example.... bass... so...
Code: Select all
$badWords = "/\b(f***|s***|a******|a**|c***|d***|b****)\b/ie";