Solved

profanity checker

Posted on 2001-08-16
3
295 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

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…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
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…

617 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