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

(This post was last modified: 09-30-2016, 05:44 PM by InsiteFX. Edit Reason: fix badwords mistake. )

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('badword''Your message has a band words <b>' $badFound '</b>you can not use those words.');
 
             }

 
             return false       
        
}
 
       else
        
{
 
           return true;
 
       }
 
   }

What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Messages In This Thread
RE: Display a set_message for each bad wor found in string - by InsiteFX - 09-30-2016, 04:17 AM



Theme © iAndrew 2016 - Forum software by © MyBB