Welcome Guest, Not a member yet? Register   Sign In
Display a set_message for each bad wor found in string
#7

(09-30-2016, 04:17 AM)InsiteFX Wrote: Rough try, not tested see if it will get you started.

Old saying get it to work first then throw in all the bells and whistles.

PHP Code:
class MY_Form_validation extends CI_Form_validation {

 
   public function badword($string)
 
   {
 
       // Dummy words
 
       $badWords = array("ban","bad","user","pass","stack","name","html");

 
       $badFound '';
 
       $badCount 0;

 
       $matches  = array();
 
       $matchFound preg_match_all("/\b(" implode($badWords,"|") . ")\b/i"$string$matches);

 
       if ($matchFound)
 
            
              $words 
array_unique($matches[0]);
 
             
              foreach
($words as $word)
 
             {
 
                 $badFound =. $word ' ';
 
                 $badCount++;
 
             }
 
             
              if 
($badCount == 1)
 
             {
 
                 $this->set_message('badword''Your message has a band word <b>' $badFound '</b>you can not use that word.');
 
             }
 
             else
              
{
 
                 $this->set_message('badwords''Your message has a band words <b>' $badFound '</b>you can not use those words.');
 
             }

 
             return false       
        
}
 
       else
        
{
 
           return true;
 
       }
 
   }



Thank you
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply


Messages In This Thread
RE: Display a set_message for each bad wor found in string - by wolfgang1983 - 09-30-2016, 01:11 PM



Theme © iAndrew 2016 - Forum software by © MyBB