Home Register Members List Search Today's Posts Mark Forums Read

Go Back   TechFuels Forum > Software > Applications

Reply
 
LinkBack Thread Tools
techno23
Senior Member
 

techno23 is offline  
Old 02-06-2008, 08:09 AM
  #1 (permalink)
Block Offensive Language from your Site

LotS of websites nowadays have incorporated interactive features, such as blogs, comments, views, ete. These allow visitors to post their comments online. While it's good to have such features, they can also become a lia¬bility when users start posting offensive or derogatory comments on the website. That ultimately affects the website's repu¬tation.
If you are also struggling to save your website's reputation, then here's a simple way out.

In this article, we provide you a PHP code snippet that will help you stop banned words from being posted on your website or blog, by anonymous visitors.

First of all, list down all words in a text file that you want to ban. Then, write down a function 'check_offensive_ word()', which will be responsible for checking each word written on your website for being an offensive word.The code

for the same is as follows: <?php
function language_filter($string) { $offensive = @file("path/to/your/file/bad_lang.dat" );
foreach ($offensive as $curse_word) { if (stristr(trim($string),$curse_word» { $length = strlen($curse_word); for ($i = 1; $i <= $length; $i++)
}
$string =
e reg_rep la ce ( $ curse_word. $sta rs, tri m ($ string»;
$stars = "";

When the string is passed to this function, the string is parsed and checked for any offensive word that you have specified in the file 'bad_lang.dat'. It takes a word at a time from the string and checks if the word is present in the 'bad_Iang.dat'. If the word is present in the list of offensive words then it simply calculates the length of the word and replaces it with a sequence o['*'s.
The 'ere~replace' is an in-built func¬tion in PHP which replaces offensive words with the character you define, which in this case is '*'.
For testing this, write the following code snippet:
<?php
$string = "test for offensive words."; print language_filter($string);
If you have defined the word 'offen¬sive' in your banned words list, then the output of the above code will be:
This little code will make your web-
pages a little cleaner.


Name:  179.jpg
Views: 463
Size:  32.4 KB
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT +1. The time now is 05:15 PM.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.0
Copyright Techfuels -->
SEO by SubmitEdge


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151