Home >> Snippet List >> Snippet

Name
Censor Message Text
Description
Fill the "$bw" string with bad words separated by a pipe symbol and then run your text through it
PHP Snippet
<?PHP 
 
  $bw = "words|seperated|by|pipe|symbols";   
  FUNCTION str_repeats($input, $mult) {   
    $ret = "";   
    WHILE($mult>0) {   
      $ret .= $input;   
      $mult --;   
    }   
    RETURN $ret;   
  }   
  FUNCTION censorMsg($msg, $replacement="*") {   
    GLOBAL $bw;   
    $badwords = EXPLODE("|", $bw);   
    $eachword = EXPLODE(" ", $msg);   
    FOR($j=0;$j<count($badwords);$j++) {   
      FOR($i=0;$i<count($eachword);$i++) {   
        IF(IS_INT(STRPOS(STRTOLOWER($eachword[$i]), $badwords[$j]))) {   
          $msg = EREGI_REPLACE($eachword[$i],   
                               str_repeats($replacement,   
                                           STRLEN($eachword[$i])),   
                               STRIPSLASHES($msg));   
        }   
      }   
    }   
    RETURN $msg;   
  }   
  $msg = $_POST["msg"];   
  IF (ISSET($msg)) {   
    $msg = censorMsg($msg,"*");   
    PRINT "Your posted Message :<br>".$msg;   
  }   
?>