Word Filter Function

in

using this function we can filter bad words in sentences





<?php
function wordfilter($sentence) {
  $badlist = array ("dog","pig","monkey");
  foreach($badlist as $badword){
    $change="";
    $wordcensor = preg_split('//', $badword, -1, PREG_SPLIT_NO_EMPTY); 
                  // split word into character
    foreach ($wordcensor as $key => $crctr ) {  // char checking
      $crctr = eregi_replace("([aiueo])","*",$crctr); // change vowels into *
      $change.=$crctr; //join char into word
    }
    $sentence = eregi_replace ($badword,$change,$sentence);
  }
  return $sentence;
}
?>





Usage :


$sentence = "There are monkey, dog, cat, pig in backyard";
echo wordfilter($sentence);
// Output 
// There are m*nk*y, d*g, cat, p*g in backyard




Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.