Solved

profanity checker

Posted on 2001-08-16
3
292 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: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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

820 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