Quick Search:
Oracle PL/SQL Code Library
Find Or Post Oracle Jobs
Oracle Discussion & Chat
 PHP Code: Bad Word Filter Jump to:  
Category: >> PHP Code >> Bad Word Filter Bookmark and Share

<< lastnext >>

Snippet Name: Bad Word Filter

Description: Replaces bad words, censoring the text passed in automatically.

Also see:
» Censor Message Text
» Vulnerability Tester
» Block IP Addresses
» Ban Proxy Servers
» Anti-Flood Protection
» Anti-SQL Injection Function
» XSS Sanitizer Function
» Filter non-alphanumeric characters

Comment: (none)

Language: PHP
Highlight Mode: PHP
Last Modified: March 16th, 2009

// BadWordFilter
// This function does all the work. If $replace is 1 it will replace all bad words
// with the wildcard replacements.  If $replace is 0 it will not replace anything.
// In either case, it will return 1 if it found bad words or 0 otherwise.
// Be sure to fill the $bads array with the bad words you want filtered.
FUNCTION BadWordFilter(&$text, $replace){
     // fill this array with the bad words you want to filter and their replacements
     $bads = ARRAY (
     IF($replace==1) {                                        //we are replacing
          $remember = $text;
          FOR($i=0;$i<sizeof($bads);$i++) {               //go through each bad word
               $text = EREGI_REPLACE($bads[$i][0],$bads[$i][1],$text); //replace it
          IF($remember!=$text) RETURN 1;                     //if there are any changes, return 1
     } ELSE {                                                  //we are just checking
          FOR($i=0;$i<sizeof($bads);$i++) {               //go through each bad word
               IF(EREGI($bads[$i][0],$text)) RETURN 1; //if we find any, return 1
// this will replace all bad words with their replacements. $any is 1 if it found any
$any = BadWordFilter($wordsToFilter,1); 
// this will not repace any bad words. $any is 1 if it found any
$any = BadWordFilter($wordsToFilter,0); 

Oracle Magazine
and Oracle White Papers

SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 27 users online    © 2009 psoug.org

Forgot your password?