CoderZone.org

Category: >> PHP Code >> Censor Message Text Bookmark and Share

<< lastnext >>

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.

Also see:
» Bad Word Filter
» Remove all non-ASCII chars
» Vulnerability Tester
» Filter Empty Array Elements
» Block Selected IP Addresses
» Stop Proxy Server Access
» Naughty Word Censor
» Flood Protection Script
» SQL Injection Filter
» XSS (Cross-Site Scripting) Sanitiz...
» Strip all non-alphanumeric charact...

Comment: (none)

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

<?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;   
  }   
?>   
<form method="post"> 
<textarea name="msg" cols=50 rows=10></txtarea><br> 
<input type="submit" value="Censor It"> 
</form>
 
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 8