| Log In |
| Email: | |
| Password: | |
| Forgot Password |
| Email: | |
| Censor Words |
| PHP jQuery Javascript Demo | Browse Category | Friday, February 10, 2012 by William Thomas |
|
Tweet |
|
|
<?php
$list = array('ass', 'bitch', 'damn', 'fuck', 'shit'); //ARRAY OF WORDS TO CENSOR
$str = 'What the Fuck is that? You mothafuckin bitch!!!'; //STRING TO SEARCH THROUGH
//REPLACES EVERY WORD IN 'list' WITH THE FIRST LETTER AND ASTERICKS
for($i=0; $i<count($list); $i++){
$c = $list[$i]; //WORD IN THE ARRAY
$firstl = substr($c, 0, 1); //FIRST LETTER
$strlen = strlen($c); //NUMBER OF CHARACTER OF EACH WORD
$astr = str_repeat('*', $strlen-1); //REPLACES THE REST OF WORD WITH ASTERICKS
$censored = $firstl.$astr; //CENSORED WORD Ex: (f***)
//USED TO PREVENT a (|ass|bitch) IN REGEX
if($i==0){
$d .= $c;
} else {
$d .= '|'.$c;
}
$str = eregi_replace('('.$d.')', $censored, $str); //CENSORING PROCESS HERE
}
echo $str;
?>
| wcet2011 @TheNut the (jQuery/Javascript) error is fixed. Tuesday, April 24, 2012 at 7:48:42 PM |
| TheNut One more thing. It will change exactly those variables, so other, normal word which contains bad words will be also changed ie class => cla**** Tuesday, April 24, 2012 at 12:43:02 AM |
| TheNut Hi, I've tried this script (jQuery/Javascript) and it looks very nice, but I have 2 problems: 1. Letter size matter, so Word, WORD and word aren't the same 2. It replace every word only once, if user put 'word word word' we will get 'w**** word word' How to solve those problems? Tuesday, April 24, 2012 at 12:40:22 AM |