Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

profanity checker

Posted on 2001-08-16
3
Medium Priority
?
298 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 200 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:Richard Quadling
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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 look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

972 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