Author: Admin 02/26/2022
Language:
PHP
Tags: php bad word filter
Here's a filter you can use to remove bad words from user submitted data.
public function filterwords($text){
$filterWords = array('word1','word2','word3');
$filterCount = sizeof($filterWords);
for ($i = 0; $i < $filterCount; $i++) {
$text = preg_replace_callback('/\b' . $filterWords[$i] . '\b/i', function($matches){return str_repeat('*', strlen($matches[0]));}, $text);
}
return $text;
}