How to check bad word in string or not using php? : This is my php code for replace bad word in string to *, it's work good.

But i want to check in string have bad word or not. How can i do ?

index.php

    <?php
    include("badwords.php");
    $content = "cat fuck dog";
    $badword = new badword();
    echo $badword->word_fliter("$content");
    ?>

badword.php

    <?php
    $bad_words = array (
    	"asshole",
    	"ass",
    	"bitch",
    	"bastard",
    	"cunt",
    	"dick",
    	"dike",
    	"dildo",
    	"fuck",
    	"gay",
    	"hoe",
    	"nigger",
    	"pussy",
    	"slut",
    	"whore",
    	"god damn",
    	"goddamn"
    	);
    
    class badword {
        function word_fliter($content) {
            global $bad_words, $wordreplace;
            $count = count($bad_words);
            for ($n = 0; $n < $count; ++$n, next ($bad_words)) {
                $filter = "*";
    
                //Search for bad_words in content
                $search = "$bad_words[$n]";
                $content = preg_replace("'$search'i","<i>$filter</i>",$content);
            }
            return $content;
        }
    }
    ?>
		
............................................................................................................................................................