webcodebase.com Snippets database & Pastebin

Anti badwords script

Submitted on 04/11/2008
Authors Comment: A really simple anti badwords scripts, includes example for both array() and for mysql table.
How to use: If you're going to use a mysql table, just have 2 fields 'id', 'badword'

Change the $badword array for words that you want to be censored.
Download Snippet:
Snippet:

  1. <?php
  2. /*
  3.  
  4. * Anti badword script
  5.  
  6. * Copyright (C) 2008 Webcodebase
  7.  
  8. * Feel free to use, no license
  9.  
  10. */
  11.  
  12. // Message to be parsed with the anti-badword filter
  13. $message =      "Hello, this is a message that badworda will be replaced by stars".
  14.                 "without doubt, this will happend with badwordb and badwordc as well.";
  15.  
  16. /*     
  17.         * Character to replace the badwords with
  18.         * Default: (*)
  19. */
  20. $replace = "*";
  21.  
  22. /* Badwords, can also be loaded from a MySQL Table */
  23. $badword = array('badworda','badwordb','badwordc');
  24.  
  25. /*
  26.         * Example if done with mysql
  27.  
  28. $badword = $db->query("SELECT * FROM badwords");
  29. $badword = mysql_fetch_array($badword);
  30.  
  31. */
  32.  
  33. /* Heres the action happning */
  34. if(!empty($badword)) {
  35.         foreach ($badword as $curse_word) {
  36.                 if (stristr(trim($message),$curse_word)) {
  37.                         $length = strlen($curse_word);
  38.                         for ($i = 1; $i <= $length; $i++) {
  39.                                 $stars .= $replace;
  40.                         }
  41.                         $message = eregi_replace($curse_word,$stars,trim($message));
  42.                         $stars = "";
  43.                 }
  44.         }
  45. }
  46.  
  47. // Output the new message
  48. echo $message;
  49.  
  50. ?>

 

Comments:

  1. .zdqsii | December 11, 2008 at 18:47

    KYlpGS <a href="http://vhlrrmtfmxmx.com/">vhlrrmtfmxmx</a>, [url=http://ixyitzrqcjdd.com/]ixyitzrqcjdd[/url], [link=http://etefhynmucqj.com/]etefhynmucqj[/link], http://yzwpxvwkejsk.com/

  2. .osmnyxkt | December 11, 2008 at 18:47

    WvxbBE <a href="http://khgxcwwuiakz.com/">khgxcwwuiakz</a>, [url=http://byjqinykyame.com/]byjqinykyame[/url], [link=http://hjqhccjhxcnh.com/]hjqhccjhxcnh[/link], http://lozkwvkhvwst.com/

  3. .uafvaz | December 11, 2008 at 18:47

    7uwkhp <a href="http://afrxhmcsqdun.com/">afrxhmcsqdun</a>, [url=http://vtwadaxypwii.com/]vtwadaxypwii[/url], [link=http://omnwefziymlz.com/]omnwefziymlz[/link], http://edhpsahxoizx.com/

  4. .zbggldgwujy | December 11, 2008 at 18:47

    JNSrmh <a href="http://mqzysvwxmkxh.com/">mqzysvwxmkxh</a>, [url=http://kefovwyhdpbz.com/]kefovwyhdpbz[/url], [link=http://dfqupsyyurmi.com/]dfqupsyyurmi[/link], http://oqurudttpikp.com/

  5. .nllbwcdvgt | December 11, 2008 at 18:47

    BD0Nyz <a href="http://wwclpeemuadn.com/">wwclpeemuadn</a>, [url=http://wnywwvotvffc.com/]wnywwvotvffc[/url], [link=http://fnagxrzpfgyq.com/]fnagxrzpfgyq[/link], http://juyrlxclvbvm.com/

  6. .bjtgxkaxy | December 11, 2008 at 18:47

    bqSx6Z <a href="http://kgldoijliyeu.com/">kgldoijliyeu</a>, [url=http://yvyijxdbhcvo.com/]yvyijxdbhcvo[/url], [link=http://udjokvkgdhcg.com/]udjokvkgdhcg[/link], http://mkztnrunftnl.com/

  7. .orsfgd | December 11, 2008 at 18:47

    eRLvQ5 <a href="http://qccrdwnoxdip.com/">qccrdwnoxdip</a>, [url=http://ngjiscwfomwl.com/]ngjiscwfomwl[/url], [link=http://goosbhxrngvt.com/]goosbhxrngvt[/link], http://hjkyiumphgha.com/


New Comment:
Name:
Comment:








Latest News

  • 30/12/09
    Webcodebase is BACK & New updates.
    Hello, Because of a jackass of a friend the main files for Webcodebase was deleted. I Thought everything was lost until i found a backup folder on my old linux box, so i restored WCB Back to its original state. The staff will continue posting snippets and fighting spam. We will also start releasing tools that web masters can use to check their scripts for vulnerabilities. These scripts will have special stars next to them and the "STAFF" tag. Please use these on your own systems only, we are NOT responsible for any damage they may do. We release them purely for educational purposes only! Thanks, Head of WCB, Arne AKA Cypher....
    [Read More]