Hi, I had this code:
$censor = explode(",", $censoredwords);
foreach ($censor AS $word) {
$message = preg_replace("/".preg_quote($word, "/")."/i", "**bleep**", $message);
}
And it worked fine, and did what I wanted. However I wanted to make it into a function, so I now have this:
function censor($tocensor) {
$censorvar = explode(",", $censoredwords);
foreach ($censorvar AS $word) {
$tocensor = preg_replace("/".preg_quote($word, "/")."/i", "**bleep**", $tocensor);
}
return $tocensor;
}
With that function, I call it like this:
$message = censor($message);
However, using the new function method, it puts a "bleep" in between every character. Example: Dog changes to bleepDbleepobleepg, whether or not it is a word in the $censoredwords list. What is going wrong? Any help is appreciated, thanks! 😃