Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form-if statement complication

Status
Not open for further replies.

CGIMana

IS-IT--Management
Mar 6, 2006
56
US
Hello,
I would like to make a if statement for my form to echo
-Sorry but your answers are not acceptable due to foul language
if they use naughty word in any of the fields.
How would I go about stating that?
Code:
if(($_POST['about']=="a series fo curse words"))
{
echo "Sorry but your answers are not acceptable due to foul language"
I know the == will always make this false use less they string together the profounities together in the same order I have set. But I also want to block $ for s's |for i's @ for a's an so on aso forth.

any help or code already made for this would be helpfull. I am sure I'm not the first to wonder or do it.

-Hoped I helped. Don't forget this site is Member supported.
 
You could use a list of unallowed words, and use strpos to verify wether they are there or no. if they are you can then echo the message.

Off the top of my head:


Code:
[green]Define list of foul words[/green]
$foulwords[0]="foulword1";
$foulwords[1]="foulword2";
$foulwords[2]="foulword3";
$foulwords[3]="foulword4";

[green]Set foul word found token to false[/green]
$foundfoulword=false;

[green]Loop through list of foul words and check for macthes in submitted text[/green]
for($i=0;$i<=3;$i++){
if(strpos($text_with_foul_words,$foulwords[$i]){
[green]if at any point a foul word is matched set token to true.[/green]
$foundfoulword=TRUE;
}
}

[green]after the checking has been done check to see if foul word token is true, in which case a foul word matching one of the list was found.[/green]
if($foundfoulword==true){
echo "You have a dirty word in your text";
}

else{
echo "Text is clean";
}


Of course the list of foul words can come from a comma delimited file, or a DB or something else. And you just loop through them and see if they appear in the text.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
if you are using this for a blog comment checker or similar (i.e. with public facing output), i'd consider

+splitting the incoming value into an array (using a space as a delimeter)
+iterate the array to remove special characters
+iterate the array using soundex or metaphone to compare each array element to a list of reserved words.

this should then (pretty-much) defeat letter replacement get-arounds
 
This is for a guild application for a World of Warcraft guild. It will also go on my site for a how-to on making a form. After I get this part tackled, I'm going to learn how to send it to a data base and/or a txt file.
Thanks for the help guys.

-Hoped I helped. Don't forget this site is Member supported.
 
I'd have used preg_replace() with arrays containing badwords and their suitable replacements, at least you'd have a chance of making an unsightly text appear far more amusing.

consider:
"you F****** W*******"

which could be replaced by
"you slighly offensive person"

useage ripped unashamedly from the php manual
<?php
$string = 'The quick brown fox jumped over the lazy dog.';
$patterns[0] = '/quick/';
$patterns[1] = '/brown/';
$patterns[2] = '/fox/';
$replacements[2] = 'bear';
$replacements[1] = 'black';
$replacements[0] = 'slow';
echo preg_replace($patterns, $replacements, $string);
?>

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
@KarveR

yup: like that. particularly as you could reverse it:

input: "You f****** w**k**"
output: "I, the poster, like the 1970's pop group, Bucks Fizz"

but ... don't you think that some fuzzy logic is advantageous in these circs? for example
input: "You f*kk*** ..." would not get caught by the correctly spelled variants.

i've never really played with soundex/metaphone but i suspect that this would be a good way forward
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top