I have in php an array of banned words.
With this code I replace the banned words with * in a string:
foreach ($wordlist as $word)
if (stripos($str, $word) !== false)
$str = str_ireplace($word, str_repeat('-*', strlen($word)), $str);
return $str;
The problem is that some users add spaces within words, so the code does not find them.
Example:
Banned word: apple
If I write apple is replaced with *****
If I write ap ple isn't replaced
Is there a way to use str_ireplace
ignoring the white space?