how to validate against the "bad words"?

sales2010

Well-Known Member
Hello,

Need your help to create a php validation for bad words..i tried the code below but i can't make it work, i am able to submit the form:

Code:
$badWords = array('bad word1','bad word2','bad word3');
$text = '{tablename___element_name}';
foreach($badWords as $bad) {
if(in_array($bad, $text)) {
return false;
    } else {
return true;
    }
}

Thank you
 
oh boy :)
Suggest you read the php docs :)
in_array - requires the second parameter to be an array, you are testing against $text which may be a string?
 
Thank you, Rob. Don't know what do you mean with "oh boy", but you're right, i read the php documentation and i end with this code, maybe not the most elegant, but functional.

Code:
$badWords = array("bad word1","bad word2","bad word3");
$text = '{tablename___element_name}';
$text = explode(' ',$text);
foreach($text as $word) {
if (in_array($word,$badWords)) {
return false;
} else {
return true;
}
}
 
  • Like
Reactions: rob
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top