Now I found out any other word that include "rat" is caught(i.e brat,rattle,etc)PHP Code:$badwords = array("rat","badword2","badword3"); foreach($badwords as $word=>$key) { if(strpos($message,$key) !== false) { echo 'inappropriate content '; break; } }
Can anyone help me modify the code so it ony rejects "rat" and allow "brat" ?
Cramblibu once helped me with this code but it does not work
PHP Code:$badwords = array("rat","badword2","badword3"); $pattern = sprintf('/\b%s\b/i', implode('|', array_map('preg_quote', $badwords))); if (preg_match($pattern, $message)) { // case insensitive badword found }






Bookmarks