Following php
function is being used to replace bad words with starts but I need one additional parameters that will describe either bad words found or not .
$badwords = array('dog', 'dala', 'bad3', 'ass');
$text = 'This is a dog. . Grass. is good but ass is bad.';
print_r( filterBadwords($text,$badwords));
function filterBadwords($text, array $badwords, $replaceChar = '*') {
$repu = preg_replace_callback(array_map(function($w) { return '/\b' . preg_quote($w, '/') . '\b/i'; }, $badwords),
function($match) use ($replaceChar) {
return str_repeat($replaceChar, strlen($match[0])); },
$text
);
return array('error' =>'Match/No Match', 'text' => $repu );
}// Func
Output if badwords found should be like
Array ( [error] => Match[text] => Bad word dog match. )
If no badwords found then
Array ( [error] => No Match[text] => Bad word match. )