Hello Guys i want to replace bad word to something like this F*ck
i need fast way to do that.
For now i am using this cods its work but i need improved one
$swears = array(
"fuck" => "f**k",
"fUck" => "f**k",
"fuCk" => "f**k",
"fucK" => "f**k",
"suck" => "s**k",
"fellow" => "fe**ow"
);
str_replace(array_keys($swears), array_values($swears), $string);
You can see i was convert one word to another using many rows i need faster codes to do that.
SamA74
October 13, 2016, 2:20pm
2
You could make it easier with str_ireplace
in stead of str_replace
…
1 Like
chorn
October 13, 2016, 2:34pm
3
how much faster in milliseconds? and how comes this is the bottleneck of your entire application?
i want to replace bad words
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…
People are always going to be able to get around a swear word filter no matter hard you try.
2 Likes
system
Closed
January 21, 2017, 6:10pm
8
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.