Page 1 of 1

Filtering badwords in GBook

Posted: Thu Jul 06, 2006 6:51 am
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

Posted: Thu Jul 06, 2006 11:46 am
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**",

Posted: Thu Jul 06, 2006 1:42 pm
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

Posted: Sun Jul 09, 2006 2:47 pm
by Klemen
How about adding \b before and after the bad word (used in regular expressions for word boundary)?

Code: Select all

\bass\b

Posted: Sun Jul 09, 2006 2:51 pm
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.

Posted: Sun Jul 09, 2006 3:20 pm
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

Posted: Sun Jul 09, 2006 3:28 pm
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

Posted: Sun Jul 09, 2006 9:17 pm
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,

Posted: Sun Jul 09, 2006 10:14 pm
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

Posted: Wed Jul 12, 2006 10:34 am
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

Posted: Wed Jul 12, 2006 10:59 am
by Klemen
Hey, no problem at all! Not sure why they would reject it but thanks for trying anyway!