1

I use code below to check if comment contains any word in array below. It returns true if detect word.

$blacklist = array("fuck","shit","pussy", "mail.ru","viagra pill", "bitcoin", "конце", "pharmacy", "bad credit","casinos");
function checkblacklist($commnetct) {
  foreach ($blacklist as $word) {
    if (strpos($commnetc, $word) !== FALSE) { 
        return true; 
        break;
    }
  }
}

Then I use

if(checkblacklist($stringcomment)) {

}

Can you help me to check if something wrong because it does not work

7
  • Can you elaborate on "does not work"? Are you getting an error? The wrong result? Commented Dec 9, 2018 at 8:43
  • 2
    Your parameter is $commnetct and in your check you are using $commnetc. Commented Dec 9, 2018 at 8:46
  • You also don't need break after the return as it will never get there. Commented Dec 9, 2018 at 8:47
  • @NigelRen haha I see. thank you :D Commented Dec 9, 2018 at 8:47
  • What's wrong with mail.ru?)))) Commented Dec 9, 2018 at 9:04

1 Answer 1

2

You did not passed parameters in your function

Follow this code

$blacklist = array("fuck","shit","pussy", "mail.ru","viagra pill", "bitcoin", "конце", "pharmacy", "bad credit","casinos");
function checkblacklist($commnetct,$blacklist) {
    foreach ($blacklist as $word) {
        if (strpos($commnetct, $word) !== FALSE) {
            return true;

        }
    }

    return false;
}

$stringcomment = "shit";
if(checkblacklist($stringcomment,$blacklist)) {
    echo "true";
}else{
    echo "false";
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.