Answer the question
In order to leave comments, you need to log in
Replacing bad words in a message with asterisks
I am replacing bad words in messages with PHP.
I did not find a ready-made solution, I do something like this:
public static function replaceFuckWords($message)
{
$pattern = '/ahole|ash0le|f u c k|bi.+ch/i'; // здесь сейчас не все слова, список будет большой
return preg_replace($pattern, '*****', $message);
}
Answer the question
In order to leave comments, you need to log in
You can modify your code like this:
function replaceFuckWords($message)
{
$pattern = '/(ahole|ash0le|f u c k|bi.+ch)/ie';
return preg_replace($pattern, "str_repeat('*', strlen('$1'))", $message);
}
The simplest search in Google - www.awsinternet.com/articles/2005/PHP_Bad_word_vulgar_word_filter.html
Here Kohana has a method in the Text class for replacing matyukov .
For example cipa, you need to replace with **** (four asterisks)Part****tion .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question