Solved

profanity checker

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

863 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

21 Experts available now in Live!

Get 1:1 Help Now