Solved

profanity checker

Posted on 2001-08-16
3
289 Views
Last Modified: 2011-09-20

I am setting up a system where other webmasters will be able to add a link to their site on my page.  It will include title and a summary.

With the script I am writing I am checking on several things, stripping out tags, that type of thing.

One of the things I need to do is screen out profanity.  I wrote this:

/*test for jerks*/
$profanearray = array('xxx','porn','sex'  /*hardcore words left out for this example*/  );
foreach ($profanearray as $profanity) {
if (strstr($title, $profanity)){$result='reject';}
if (strstr($summary, $profanity)){$result='reject';};
}
if ($result=='reject';){include ("reject.inc");}


I have about 45 words I am screening for right now.  Am I going about this the right way or is there a more efficient way to do this?

If there is a better function (or set of functions) for accomplishing the same thing please point me in the right direction.  I don't need a script written, I am getting the hang of this (sort of).


0
Comment
Question by:ChrisAndrews
3 Comments
 
LVL 3

Accepted Solution

by:
izwiz earned 50 total points
ID: 6395994
I would say thats probably sort of the way to do it actually.

The only problem I can see there is that you are still iterating through the whole list of words (which, if it grows may start taking time) once you have found a match.


I would place the code in a function and return rejection, thus halting execution at that point:

function jerk_test($title, $summary) {

/*test for jerks*/
$profanearray = array('xxx','porn','sex'  /*hardcore words left out for this example*/  );
foreach ($profanearray as $profanity) {
if (strstr($title, $profanity)){return 'reject'}
if (strstr($summary, $profanity)){return 'reject';};
}

return 'keep';
}

Then call it from your code:

if (jerk_test($title, $summary) == 'reject')
{
include ("reject.inc");
} else {
//Do something else
}


Oh, and you might want to use stristr() instead as it's case insensitive.

Hope this helps.






0
 
LVL 40

Expert Comment

by:RQuadling
ID: 6396410
You should also include the URL and then read the actual page you are linking to.

If you are automating this, then watch out for sites like expertsexchange as we all know the trouble THAT one caused and Scunthorp United football (soccer) team had a laugh getting THEIR domain working within schools!

Regards,

Richard Quadling.
0
 

Author Comment

by:ChrisAndrews
ID: 6398241

Great ideas, I will implement them.

Thank you :)

Chris
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now