Re: Form Data Filtering
| From: | kvigor | Date: | Sat, 16 Jun 2007 13:06:18 +0000 |
| Subject: | Re: Form Data Filtering | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-257170@lists.php.net to get a copy of this message | ||
if (in_array(strtolower($value), $profanity))
{
$profanity[$field] = "bad";
}
on php.net I haven't seen any example on using strtolower w/ arrays.
I tried this an I get the following output:
Please REMOVE the profanity in the following fields. Immediately!
Notice: Undefined offset: 0 in C:\htdocs\Sweepstakes\sosValidate.php on line
114
Notice: Undefined offset: 1 in C:\htdocs\Sweepstakes\sosValidate.php on line
114
Notice: Undefined offset: 2 in C:\htdocs\Sweepstakes\sosValidate.php on line
114
Notice: Undefined offset: 3 in C:\htdocs\Sweepstakes\sosValidate.php on line
114 ...etc.
I also tried (in_array(strtolower($_POST[$value]), $profanity)) same
result.
"Stut" <stuttle@gmail.com> wrote in message news:4672A282.20005@gmail.com...
> kvigor wrote:
>> I 'm checking form data for profanity but it only works if the
>> $_POST['var'] is lowercase I was wondering if anyone knew how I could
>> catch the profanity no matter what case it was. No matter if it was BAD
>> or bad or mixed like BaD?
>>
>> Instead of the long way:
>>
>> if ($value == "fuck" || $value == "shit" || $value == "whore"
>> || $value
>> == "shit" || $value == "bullshit" || $value == "ass" ||
>> $value ==
>> "asshole" || $value == "piss" || $value == "bitch" || $value
>> == "bastard"
>> || $value == "motherfucker" || $value == "pussy" || $value ==
>> "cunt" ||
>> $value == "slut" || $value == "hell" || $value == "goddamn"
>> || $value ==
>> "skank" || $value == "Tit" || $value == "dick" || $value ==
>> "hoe")
>> {
>> $profanity[$field] = "bad";
>> }
>
> Now that's some bad code cheesy!
>
>> Any suggestions welcome.
>
> Try this on for size...
>
> $badwords = array('fuck', 'shit', 'whore', etc...);
> if (in_array(strtolower($value), $badwords))
> {
> $profanity[$field] = 'bad';
> }
>
> -Stut