Filtering badwords in GBook

Dr. GBooky is here to help you with your guestbook problems ...
Post Reply
Coderunner
Posts: 6
Joined: Thu Jul 06, 2006 6:15 am

Filtering badwords in GBook

Post by Coderunner »

Hello,

I have a question about the bad words filter in GBook v.1.4*.

Probleem 1
When somebody enters words as a$$, pu$$y, etc. (so words with the dollar signs) than the words aren't filtered even when I add these words in the en.php

Code: Select all

"a$$" => "***",
Problem 2
If they write the word e.g. "ass" in the beginning or at the end of a sentence so without spaces, than the word isn't filtered either.
When I add

Code: Select all

"ass " => "***",
or

Code: Select all

" ass" => "***",
than words as pass, password, passing etc ... become p***, p***word, p***ing etc.

How can I fix these 2 problems ?

Thanks in advance for you help.
Kind regards,
Coderunner

Corrected and changed in post: badwords.txt to en.php
Last edited by Coderunner on Thu Jul 06, 2006 1:47 pm, edited 2 times in total.
Klemen
Site Admin
Posts: 10141
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

Hi,

The thing is those code in bad words is entered in PHP in a regular expression. You should try with:

1. for $ signs use \\\$, for example:

Code: Select all

"a\\\$\\\$" => "***",
2. for spaces use \s and add an empty space before the corrected word

Code: Select all

"\sass" => " a**",
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Coderunner
Posts: 6
Joined: Thu Jul 06, 2006 6:15 am

Post by Coderunner »

Hello Klemen Stirn,

First of all I want to thank you for your reply and your help.
1. for $ signs use \\\$, for example:

Code: Select all

"a\\\$\\\$" => "***",
→ your solution fixed the problem :)
2. for spaces use \s and add an empty space before the corrected word

Code: Select all

"\sass" => " a**",
→ your solution fixed half of the problem (only when word is at the end of a sentence, so with a space in front).
I still get the complete word when they just write that one word without ANY spaces. :?
Eg if they fill in the name field and just write ass
as I said before when I add

Code: Select all

"ass" => " a**",
than words as pass will become p***, so that's not a good solution.
The question is: CAN this be solved ? I hope you can ;)

Kind regards,
Coderunner

PS the file isn't badwords.txt as I wrote in my first post but en.php
Klemen
Site Admin
Posts: 10141
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

How about adding \b before and after the bad word (used in regular expressions for word boundary)?

Code: Select all

\bass\b
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Klemen
Site Admin
Posts: 10141
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

Also instead of editing each bad word with \b you should simply put it in the filter_bad_words function in gbook.php, change

Code: Select all

$text = preg_replace("/$k/i",$v,$text);
to

Code: Select all

$text = preg_replace("/\b$k\b/i",$v,$text);
I will also include this in the next GBook update so other users don't have same problems.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Coderunner
Posts: 6
Joined: Thu Jul 06, 2006 6:15 am

Post by Coderunner »

Klemen Stirn wrote:

Code: Select all

\bass\b
Hello Klemen Stirn,

YEAH !!! that solved the problem ... :wink:
Thank you very very much !!!!

Kind regards,
Coderunner
Last edited by Coderunner on Sun Jul 09, 2006 10:25 pm, edited 1 time in total.
Coderunner
Posts: 6
Joined: Thu Jul 06, 2006 6:15 am

Post by Coderunner »

Klemen Stirn wrote:Also instead of editing each bad word with \b you should simply put it in the filter_bad_words function in gbook.php, change

Code: Select all

$text = preg_replace("/$k/i",$v,$text);
to

Code: Select all

$text = preg_replace("/\b$k\b/i",$v,$text);
Hello Klemen Stirn,

YEAH !!! that solved the problem too and even better, that way as you said, I don't have to add the \b to every badword in the list (en.php)!!!
Again ... Thank you very very much !!!!
I will also include this in the next GBook update so other users don't have same problems.
Good idea!!

Kind regards,
Coderunner
Last edited by Coderunner on Sun Jul 09, 2006 10:26 pm, edited 1 time in total.
Klemen
Site Admin
Posts: 10141
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

No problem, I like to help where changes benefit many GBook users. You are invited (but in no way required) to rate GBook or even post a review at
http://php.resourceindex.com/rate?05414
and/or
http://www.hotscripts.com/Detailed/37192.html

Regards,
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Coderunner
Posts: 6
Joined: Thu Jul 06, 2006 6:15 am

Post by Coderunner »

Klemen Stirn wrote:No problem, I like to help where changes benefit many GBook users. You are invited (but in no way required) to rate GBook or even post a review at
http://www.hotscripts.com/Detailed/37192.html

Regards,
Hello Klemen Stirn,

I did what you asked because I really appreciate:
1- that you share your interesting scripts
(NOTE: even for free which makes it even more interesting :wink: hehehe)
2- and of course for your fast replies to my questions which solved my problems !!

Thanks again Klemen Stirn.

Kind regards,
Coderunner
Coderunner
Posts: 6
Joined: Thu Jul 06, 2006 6:15 am

Post by Coderunner »

Klemen Stirn wrote:You are invited (but in no way required) to rate GBook or even post a review at
http://www.hotscripts.com/Detailed/37192.html
Regards,
Hello Klemen Stirn,

As I said in my earlier post, I wrote a review but for some reason they rejected it and I really don't know why. I just wrote what good features your guestbook has and that you have a good support forum and that you reply very fast.

Sorry ... :cry:

Kind regards,
Coderunner
Klemen
Site Admin
Posts: 10141
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

Hey, no problem at all! Not sure why they would reject it but thanks for trying anyway!
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Post Reply