HS Banner
Back
Bad Word Filter

Author: Admin 02/26/2022
Language: PHP
Views: 314
Tags: php bad word filter


Description:

Here's a filter you can use to remove bad words from user submitted data.

Article:

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;
    }



Back
Comments
Add Comment
There are no comments yet.