Nov 8, 2009

Badword Filter In Php To Reduce Spam? - Restrict vulgur words on the webpages

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming > Programming General

Badword Filter In Php To Reduce Spam? - Restrict vulgur words on the webpages

veerumits
Badword Filter in php to reduce spam?

Actually friends i want to integrate badword filter on one of my webpage, which is filled by the users, so i want to replace all those vulgur words with some special characters. this is very much problematic for me now a days , and i think by this way, any one can also hack my website. i have already gone through numerous technique(like array mechanism , by using preg_replace()etc) but not got the best one.all of them are lenthy and complex way,i think this is not a big problem by using just a simple script we can solve this problem.


so i need the simlest code for that, which is easily understandable. and it can be easly integrated with my original script .



thanx!!!!!!!!

Comment/Reply (w/o sign-up)

Quatrux
Even though you might think that bad words filtering is a good idea, in fact it isn't, practically it isn't useful at all, because bad words can still be published by for example doing something like:

if you know that a badword is badword1 then I still can post bad-word1 by adding a - symbol or a space or lets say by adding a letter: baddword! so you won't really stop swearing!!

And for English language, there are quite big databases with swearing words, which in my opinion is just useless, well unless to you on the most popular ones, but for example what about other languages? it's usually a problem by adding other languages swearing, so if you really want to do something, do something else biggrin.gif

The simplest way is in my opinion just to do this:

CODE
<?php

$words = array('badword1','badword2');

$post = str_replace($words, "****", $post);

?>


and the $words array can be got by reading a mysql database table with swearing words or you could just read a file with swearing words with a function file(); which will create an array with a value on every new line, it's your choice, also a different algorithm for ***** could be created, but say doing b*d*o*1 -> badword1 that people would see swearing..

So this code will just replace all the words found in $post string, the words are got from the $words array.. and those bad words will be replace into ****, just as simple as that smile.gif

 

 

 


Comment/Reply (w/o sign-up)

veerumits
QUOTE(Quatrux @ Nov 29 2008, 01:28 AM) *
Even though you might think that bad words filtering is a good idea, in fact it isn't, practically it isn't useful at all, because bad words can still be published by for example doing something like:

if you know that a badword is badword1 then I still can post bad-word1 by adding a - symbol or a space or lets say by adding a letter: baddword! so you won't really stop swearing!!

And for English language, there are quite big databases with swearing words, which in my opinion is just useless, well unless to you on the most popular ones, but for example what about other languages? it's usually a problem by adding other languages swearing, so if you really want to do something, do something else biggrin.gif

The simplest way is in my opinion just to do this:

CODE
<?php

$words = array('badword1','badword2');

$post = str_replace($words, "****", $post);

?>


and the $words array can be got by reading a mysql database table with swearing words or you could just read a file with swearing words with a function file(); which will create an array with a value on every new line, it's your choice, also a different algorithm for ***** could be created, but say doing b*d*o*1 -> badword1 that people would see swearing..

So this code will just replace all the words found in $post string, the words are got from the $words array.. and those bad words will be replace into ****, just as simple as that smile.gif



You are saying right that what we replace in place of bad word it is placed something else but bad word is still in the massage. ok but it not give direct effect to our reader who read topic, there is only try to restrict the bad word in the post, if known badword are restricted or replace in post then i think is good. practice, and it civilized the topic.

after some googling i found the solution just what you reply here but i want to restrict the bad word not replace the word, if any body post a badword then it is spam the user. so user can not take chance to post bad word.

thanks

Comment/Reply (w/o sign-up)

Quatrux
I don't understand you, if a badword is found in the post you want to replace it to a null value? so just do "" or '' and not "*****" ... but because of that the post might seem difficult to read because of the missing bad word !!!

Or you want to do this: if in a post a bad value accrued then don't even let that user post that message? It's really a stupid idea, but to achieve it you would need to do something like this:

CODE
<?php

$words = array('badword1', badword2);

if (in_array($words, $post) ) { don't let the user post } else { post the message }

?>


I think it should work, $words is an array in an in_array() function or else if it would work, you could find another function or maybe just do a for cycle, this is the most basic logic though.

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)


See Also,

*SIMILAR VIDEOS*
Searching Video's for badword, filter, php, reduce, spam, restrict, vulgur, words, webpages
advertisement



Badword Filter In Php To Reduce Spam? - Restrict vulgur words on the webpages

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com