slyte33 Posted March 3, 2010 Share Posted March 3, 2010 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! Link to comment https://forums.phpfreaks.com/topic/194059-list-of-foul-words-and-converting-convert-just-whole-word/ Share on other sites More sharing options...
teamatomic Posted March 3, 2010 Share Posted March 3, 2010 Word boundary \b(ass|piss)\b HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/194059-list-of-foul-words-and-converting-convert-just-whole-word/#findComment-1021102 Share on other sites More sharing options...
slyte33 Posted March 3, 2010 Author Share Posted March 3, 2010 Word boundary \b(ass|piss)\b HTH Teamatomic I'm sorry, I'm not sure I understand. Link to comment https://forums.phpfreaks.com/topic/194059-list-of-foul-words-and-converting-convert-just-whole-word/#findComment-1021103 Share on other sites More sharing options...
teamatomic Posted March 3, 2010 Share Posted March 3, 2010 if (preg_match("/\b".$FoulWord."\b/i", $ToFilter)) HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/194059-list-of-foul-words-and-converting-convert-just-whole-word/#findComment-1021141 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.