Re: Help w/ regular expressions for banned words
| From: | CC Zona | Date: | Sat, 20 Jan 2001 17:20:41 +0000 |
| Subject: | Re: Help w/ regular expressions for banned words | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-35813@lists.php.net to get a copy of this message | ||
In article <B68F2A37.47AD%lists@jumpinternet.com>, lists@jumpinternet.com
(Team JUMP) wrote:
> $num=count($bannedwords);
> for($i=0;$i<$num-1;$i++)
> {
> $string =
> eregi_replace("\b$bannedwords[$i]\b","[censored]",$string);
> }
>
>
> For whatever reason, no word in $bannedwords will match in the string. I've
> tested it with simple expressions like "\btest\b" and it will not match the
> word "test".
Have you tried it with either "[:space:]$bannedwords[$i][:space:] or
"\<$bannedwords[$i]\>" yet? Also, I think using a foreach($bannedwords as
$current_word) would be a better choice here; more compact, and loops all
the way to the end of the array even when the numerical index does not
follow the expected sequence. (BTW, if you want to stick with the for()
and you know the index numbers will always be sequentially zero to
whatever, then your test should be just $i<$num. Otherwise, you're
skipping the final loop.)
--
CC