The following lines of code are part of a function to strip a list of cesored words from being written to my database.
$txt = preg_replace("#($find)\s#si", $replace." ", $txt);
$txt = preg_replace("#\s($find)\s#si", " ".$replace." ", $txt);
$txt = preg_replace("#\s($find)#si", " ".$replace, $txt);
$txt = str_replace(" " . $find, " " . $replace, $txt);
$txt = str_replace($find . " ", $replace . " ", $txt);
$txt = str_replace($find . "%", $replace . " ", $txt);
The problem is that if the first word in the submission is immediately followed by another character (such as a comma, asterisk, etc.) the censored word slides though. So far I cannot seem to fix this.
Any ideas?
$txt = preg_replace("#($find)\s#si", $replace." ", $txt);
$txt = preg_replace("#\s($find)\s#si", " ".$replace." ", $txt);
$txt = preg_replace("#\s($find)#si", " ".$replace, $txt);
$txt = str_replace(" " . $find, " " . $replace, $txt);
$txt = str_replace($find . " ", $replace . " ", $txt);
$txt = str_replace($find . "%", $replace . " ", $txt);
The problem is that if the first word in the submission is immediately followed by another character (such as a comma, asterisk, etc.) the censored word slides though. So far I cannot seem to fix this.
Any ideas?