I have an array $bad_words containing English rude words and their dotted out equivalents and I use preg_replace_callback as follows:
$bad_words = array(
"badword" => "s••t",
"badword2" => "f••k"
...
);
function filter_bad_words($matches)
{
global $bad_words;
$replace = $bad_words[$matches[0]];
return isset($replace) ? $replace : $matches[0];
}
// $JSON is a string variable
preg_replace_callback('!\w+!', 'filter_bad_words', $JSON);
This solution is not case insensitive and I cant figure out what parameter to pass to the preg_replace_callback to make it case insensitive.
Thank you for help