----- Original Message ----- 
From: Mike Brandonisio 

Hi Bob,
How do you deal with "500 or more "X"s with no spaces"?

You could explode the posted message on [space] and do a strlen() on 
each position in the array? Then test for strlen() greater than 60 
characters. If you get a hit do str_replace() on the original message 
with an empty string.

Do you do it another way?
==============================

Hi Mike,
I originally searched through the words, then used a regex:
// any character repeated >=3 convert to 2
$raw = preg_replace('/(.){3,}/', '$1$1', $raw);

But I thought it might be hogging the processor too much on a shared server, 
especially with a large message. I seem to remember reading that preg_replace() 
with backreferences consumes a lot of cycles, and I'd just heard about a couple 
of people being throw off shared servers for hogging.

I'd forgotten I'd taken it out, and might use your method with str_replace().

Here's a easy little swear filter for anyone interested, but needs a bit more 
work. It copes with A-S-S_H*O*L*E or A S S H O L E etc. as that was one way of 
defeating filters, but has trouble with anyone living in Scunthorpe. I think it 
would need to loop through again with spaces in, or make Scunthorpe an 
exception.

function profanity_test($content) {
  global $swear;
  $banned_words = array('asshole', 'list of words etc');
  //stripout everything except text and numbers
  $content = preg_replace('/[^A-Za-z0-9]/', '', $content);
  foreach ($banned_words as $found) {
    if (preg_match("/$found/i", $content)) {
      $swear = '<b style="color:red">'.strtoupper($found).'</b>';
    }
  }
}

profanity_test($message);
if ($swear) echo "<li>Profanity $swear detected</li>";

Regards, Bob E.



Community email addresses:
  Post message: [email protected]
  Subscribe:    [EMAIL PROTECTED]
  Unsubscribe:  [EMAIL PROTECTED]
  List owner:   [EMAIL PROTECTED]

Shortcut URL to this page:
  http://groups.yahoo.com/group/php-list 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-list/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to