I have this PHP Code, it generates random characters where there is a bad word:
$wordreplace = array (
\"!\",
\"#\",
\"@\",
\"&\",
\"^\",
\"$\",
for replace bad words in string you can use preg_replace_callbackto perform a regular expression search and replace using a callback.
below example replace all bad words with *
output :
PHP is a ***ular general-purpose scripting language that is especially suited to web *****opment.
$value) {
$start = strpos($ocr[0],$value);
if($start!== false){
$length = strlen($value);
$newstr = substr_replace($ocr[0],str_repeat("*",$length),$start,$length);
}
}
return $newstr ? $newstr : $ocr[0];
}
?>