Jump to content


This topic is now archived and is closed to further replies.


Need help with a Userid Filter

Recommended Posts

Basically, i'm writing a function that would check a userid for profanity similar to msn and yahoo userid filters so for example [b]f-shit.4m[/b] would not be accepted as a proper userid (also userids must start with a letter and can only contain letters, numbers, hyphens, underscores and dots). Anyway, the banned words would be stored in a mysql database and userid passed by the form would be checked against it. The problem is i need to know if im on the right track with the following code:

$sql = "SEARCH profanity FROM filter";
$result = @mysql_query($sql);
while ($words = @mysql_fetch_array($result, MYSQL_BOTH) {
$profanity[] = $words[profanity];
$kill_characters = array ('.', '-', '_');
$kill_num = range(0,9);
$kill_all = array_merge($kill_num, $kill_characters);

$userid = str_replace($kill_all, '' ", $userid);

$obscene = $profanity[];
foreach ($obscene as $obscenities) {
if (stristr(trim($userid), $obscenities)) {
  $match = similar_text($userid, $obscenities, $percent);
  $percent = round($percent, 2);
  if ($percent >= '50') {
   echo "Sorry, username $userid is too vulgar. Please select another username.";
} else {
echo "Congratulations, username $userid is available.";
} else {
echo "Congratulations, username $userid is available.";


Where am i going wrong?   ???

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.