/    Sign up×
Community /Pin to ProfileBookmark

updated bad word filter- explode it?

I am using a simple but effective “bad word” filter on my site –

Bad_word Filter code:

[code]

$bad_words = explode(‘|’, ‘badword1|badword2|badword3|etc|etc’);
foreach ($bad_words as $naughty)
{
$comments = eregi_replace($naughty, “#!@%*#”, $comments);
}

[/code]

but as always when you solve one little problem you come up with another, those pesky kids and their rude #!@%*# words.

As I’ve added words to the filter they are replaced with other words where one or more characters have been replace with symbols or digits. i.e. in the word ‘*****’, [sorry for any offence to Meredith Brooks fans, or anybody else for that matter] this is easily be filtered on its own using a list, but the same word spelt ‘8itch’, B1tch, Bi+ch etc. could be equally offensive.

Any ideas? (Short of trying to work out every connotation of every word)

Mouse

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogOct 20.2006 — Here's what I've come up with after thinking about it a bit:
[code=php]
<?php
$altChars = array
(
'/a/i' => '[a@]',
'/b/i' => '[b3]',
'/i/i' => '[i!|]',
'/s/i' => '[s$5]',
'/t/i' => '[t+]',
'/z/i' => '[z2]'
);
$badWords = array
(
'bismuth',
'bastion',
'stable'
);
function makeRegex(&$word, $key, $altChars)
{
$word = ('/'.preg_replace(array_keys($altChars), $altChars, $word).'/i');
}
array_walk($badWords, 'makeRegex', $altChars);
$comments = 'Bi$mu+h and B@ST!ON are not words often associated with sTa3lEs';
echo preg_replace($badWords, '#####', $comments);
?>
[/code]
×

Success!

Help @Mouse77e spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...