RE: [PHP] dirty words
| From: | Graham Cossey | Date: | Sat, 16 Oct 2004 20:48:24 +0000 |
| Subject: | RE: [PHP] dirty words | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-199641@lists.php.net to get a copy of this message | ||
To be case insensitive using PHP < 5 I guess you would have to preg_split()
then iterate through each array element converting to lowercase before doing
the comparison, something like below, or include all case combos in your
$badwrds array, ie poo, Poo, POO etc.
$string = file_get_contents($url);
$wordArray = preg_split(your_regex, $string);
foreach ($wordArray as $word)
{
if (in_array(strtolower($word),$badwords))
{
$string = str_replace($word, '***', $string);
}
}
Or something along those lines. It's been a long day...
Someone here will surely post a much simpler solution :)
Graham
> -----Original Message-----
> From: Kevin Waterson [mailto:kevin@oceania.net]
> Sent: 16 October 2004 16:12
> To: php-general@lists.php.net
> Subject: Re: [PHP] dirty words
>
>
> This one time, at band camp, Mag <genphp@yahoo.com> wrote:
>
> > Hi,
> > I am useing file_get_contents on a remote page then
> > using stristr() to make sure there are no "bad words"
> > and its a family site.
> > Right now I am checking for just 3 bad words which
> > means 3 stristr() function calls, but if the bad words
> > increase then that would mean more calls....
>
> $badwords = array('poo', 'bum', 'perl');
>
> $goodString = str_replace($badwords, '***', file_get_contents($url);
>
> echo $goodString;
>
> If you are using php5 you can use str_ireplace() for a case insensitive
> search
>
> Kevin
> ---------
> "Democracy is two wolves and a lamb voting on what to have for lunch.
> Liberty is a well-armed lamb contesting the vote."
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>