Re: Profanity Filter
| From: | Ignacio Vazquez-Abrams | Date: | Mon, 22 Jan 2001 16:27:13 +0000 |
| Subject: | Re: Profanity Filter | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-36018@lists.php.net to get a copy of this message | ||
On Sat, 20 Jan 2001 Website4S@aol.com wrote:
> Ok,
>
> I am now using the following code to check if there is any profanity in the
> $FirstName however it just doesn`t work when testing, I am thinking it has
> something to do with the way I`m loading the file, any better ways.
>
> $words=file('words.txt');
> $done=false;
> while ((list($key, $val)=each($words)) and $done==false)
> {
> $done=strpos(strtolower($FirstName), $val);
> };
> if (!$done==false)
> {
> echo "Oops! Bad name";
> }
> else
> {
> echo"Okay, valid name.";
> };
>
It may have to do with the fact that you're using == in the while instead of
=== to also include type checking. If you're using PHP 3 you should say
!strlen($done), otherwise the while clause will be true if the profane word
starts at the beginning of the string (position 0).
--
Ignacio Vazquez-Abrams <ignacio@openservices.net>