PHP: replace all bad words with some text

The following script will replace all bad keywords with *** .  The keyword variable accepts multiple keywords, they must be separated with a comma (,) .

$bad_keywords="serial,hack,crack";
if($bad_keywords!="")
{
$bad_keywords=str_replace(",",")|(",$bad_keywords);
$bad_keywords="/($bad_keywords)/i";
$filepath=preg_replace($bad_keywords, "****", $filepath);
}

Leave a Reply

Your email address will not be published. Required fields are marked *