Jump to content
Sign in to follow this  
jasonc

how do I correctly check a string for bad words

Recommended Posts

function checkUsernameIsCleanOfBadWords($string) {
    $badWords = "[";
    $badWords.= "ARSE|";
    $badWords.= "*******|";
    $badWords.= "*****|";    //    i
    $badWords.= "B1TCH|";    //    one    
    $badWords.= "BLTCH|";    //    L
    $badWords.= "BOLLOCKS|";//    oh oh
    $badWords.= "BOLL0CKS|";//    oh zero
    $badWords.= "B0LLOCKS|";//    zero oh
    $badWords.= "B0LL0CKS|";//    zero zero
    $badWords.= "****|";    //    oh
    $badWords.= "C0CK|";    //    zero
    $badWords.= "CLIT|";    //    L i
    $badWords.= "CIIT|";    //    i i
    $badWords.= "CILT|";    //    i L
    $badWords.= "CLLT|";    //    L L
    $badWords.= "C11T|";    //    one one
    $badWords.= "CL1T|";    //    L one
    $badWords.= "C1LT|";    //    one L
    $badWords.= "****|";
    $badWords.= "dickhead|";//    i
    $badWords.= "dLckhead|";//    L
    $badWords.= "d1ckhead|";//    one
    $badWords.= "fanny|";
    $badWords.= "****|";
    $badWords.= "gay|";
    $badWords.= "lesbian|";    //    i
    $badWords.= "lesbLan|";    //    L
    $badWords.= "lesb1an|";    //    one
    $badWords.= "*****|";    //    i
    $badWords.= "pen1s|";    //    one
    $badWords.= "penls|";    //    L
    $badWords.= "pOOf|";    //    oh oh
    $badWords.= "pO0f|";    //    oh zero
    $badWords.= "p0Of|";    //    zero oh
    $badWords.= "p00f|";    //    zero zero
    $badWords.= "prick|";    //    i
    $badWords.= "pr1ck|";    //    one
    $badWords.= "prLck|";    //    L
    $badWords.= "rape|";
    $badWords.= "****|";    //    i
    $badWords.= "sh1t|";    //    one
    $badWords.= "shLt|";    //    L
    $badWords.= "wank]";
        if(preg_match(strtolower($badwords), strtolower($string))) {
        return "bad";
        }
    return "ok";
}



if (checkUsernameIsCleanOfBadWords($username) === "bad") {
// tell them so.
}

Share this post


Link to post
Share on other sites

The OP likes to post his questions on many different forums at the same time. This has already been answered on CodingForums ($badWords isn't $badwords).

Edited by Jacques1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

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.