Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 07-09-2008, 06:02 PM php bad words filter
Skilled Talker

Posts: 69
Trades: 0
Can anyone recommend a php or javascript bad words filter? There's so many out there, I am really not sure which one to use. I want one for textarea in a guestbook.

Thanks,
__________________
Matt
webmaster of
Please login or register to view this content. Registration is FREE
- Online wedding planning
weddingm is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-09-2008, 09:05 PM Re: php bad words filter
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Here's some code I wrote awhile back. Be sure to sort the array of bad words with the largest at the top.

PHP Code:
<?php
$word_list 
= array("/(reallybad)/ei",
                   
"/(bad)/ei");
$string "This sentence doesn't contain bad or reallybad words. Bad words shouldn't really be used by people unless they're reallybad people.";
echo 
preg_replace($word_list,"preg_replace('/[a-z]/i','*','\\1')",$string);
?>
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 07-10-2008, 11:21 AM Re: php bad words filter
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
I think that should be:

PHP Code:
<?php
$word_list 
= array("/(reallybad)/ei",
                   
"/(bad)/ei");
$string "This sentence doesn't contain bad or reallybad words. Bad words shouldn't really be used by people unless they're reallybad people.";
echo 
preg_replace($word_list,preg_replace('/[a-z]/i','*','\\1'),$string);
?>
or

PHP Code:
<?php
$word_list 
= array("/(reallybad)/ei",
                   
"/(bad)/ei");
$string "This sentence doesn't contain bad or reallybad words. Bad words shouldn't really be used by people unless they're reallybad people.";
echo 
preg_replace($word_list,"[Thats a bad word]",$string);
?>
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 07-10-2008, 01:53 PM Re: php bad words filter
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
I guess context would have helped. The code I replaced replaces each letter of the banned word with an asterisks. the preg_replace does actually have to be quoted for it to work correctly.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Reply     « Reply to php bad words filter
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.52938 seconds with 12 queries