| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
|
|
#1 (permalink) |
|
i'm done, son
Join Date: Jan 2005
Posts: 12,262
|
banned words script
I'm rebuilding the directory with my own backend. I'm implementing a "banned words" feature, where I can ban certain words (offensive, spam, etc). Here's the code that's checking them (it checks the title and the description for banned words). My fear is that it's going to take a lot of processing time, so I've tried to make it do as little work as possible - when it finds something, it stops and if it finds something in the $title, it doesn't check the $descr. PHP Code:
Seeing as I still consider myself a PHP/MySQL beginner (a new book on OOP is on its way via UPS!), even though it works, is there a better way to do this? |
|
|
|
|
|
#2 (permalink) |
|
I like code.
|
How about just using regular expressions and preg_replace to replace the words. An example of a possible solution. PHP Code:
If you are going to try to replace words with just blank space preg_replace wont work you will have to use str_replace or similar. |
|
|
|
#3 (permalink) | |
|
geek
|
Why go through all the loops? can't you just do something like PHP Code:
It should work... you could add "limit 1" to the SQL statement if you want a simple good/bad response. if you want to save processing power you coudl do some sort of comparison to the number of words n your title/description to the number of banned words in your database then check one or the other depending on who has less words. Cborrow's method would be fastest if your banned words list is short. Just replace preg_replace with preg_match and it's good. Quote:
|
|
|
|
|
#4 (permalink) |
|
i'm done, son
Join Date: Jan 2005
Posts: 12,262
|
I'd use the preg_replace method if I were replacing them. As it stands, this is just another error check on a form submission. Thanks for the suggestion, gk. I'll see what I can do with a query. Last edited by pgo : 13-05-2007 at 12:38. |
|
![]() |