Jump to content

List of Foul words and converting. Convert just whole word?


slyte33

Recommended Posts

Hello, I have created a function that will replace curse words in a text file with stars(*).

The problem I am facing, however,  is that if someone types, for example "cassie",

it will replace the string like this:

 

"C***ie";

 

What I am wanting to do, is just replace the word if it is typed as just that whole word, so it wouldn't block the 'ass' out in cassie.

 

 

Here is my function:

 

function LangFilter($ToFilter)
{
    $Foul = @file("foul.txt");
    foreach($Foul as $FoulWord) {
        $FoulWord = trim($FoulWord);
        if (preg_match("/".$FoulWord."/i", $ToFilter)) {
            $WordLength = strlen($FoulWord);
            for ($i = 1; $i <= $WordLength; $i++) {
                $RepChar .= "*";
            }
            $ToFilter = eregi_replace($FoulWord, $RepChar, trim($ToFilter));
            $RepChar = "";
        }
    }
    return $ToFilter;
}

 

All help is much appreciated, thanks!

 

Archived

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

×
×
  • 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.