Badwords filter, finding only "whole word"
I have the following that works fine
But it finds also false badword within a longer word
Example:
I need to remove "cha"
it will rem it out of" any words cha and more"
but also in this form
"experts exchange" where if finds cha, which is indeed not OK
<?php$string = 'Experts Exchange has a lot of answers for questions.';$patterns = array();$patterns[0] = '/answers/';$patterns[1] = '/for/';$patterns[2] = '/questions/';$replacements = array();$replacements[0] = 'problems';$replacements[1] = 'to';$replacements[2] = 'solve';echo preg_replace($patterns, $replacements, $string);//Echos Experts Exchange has a lot of problems to solve.?>
Thanks,
but it does not resolve my quest, the first solution is getting the same result as what I do know.
I am looking for it not to pick up "cha" in exchange but to pick it up in a str like: this is cha a str"
as a whole word only
And the other solution I am not up to adapt it
as I did not find a way to make my array working as the pattern
it looks like:
<?php
$badwords =
array (
'zzzzz',
etc.....
http://php.net/manual/en/function.preg-replace.php
http://php.net/manual/en/function.preg-match.php