SamA74
October 13, 2016, 5:59pm
5
Yes, I gathered that.
Using str_ireplace
you would not need all the variations of capitals and lower case, which would slim down your code. You would just need an array of words (regardless of case) and another of replacements.
$find = array('feck', 'suck', 'follow');
$replace = array('f**k', 's**k', 'fo**ow');
$clean = str_ireplace($find, $replace, $string);
Or there are tools to help with this task.
Have you considered using something like this or this .
If you see the thread that comes from, there can be other complications to this.
Good evening.
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 ig…