Hi,

Friday, April 23, 2004, 11:50:56 PM, you wrote:
RD> Hi all,

RD> It's a warm sunny day and I'm trying to wrap my head around the
RD> following:

RD> I want to be able to check to see if, in a string, the user has
RD> entered too many consecutive characters and not enough spaces. For
RD> example they might enter a subject like:

RD> "hello world!!!!!!!!!!!!!!!!! how arrrrrrrrrrrrrrre you today?????!!"

RD> Does anyone have a nice technique for checking the following:

RD> 1) Count the length of the words in the string, i.e. if there are any
RD> words beyond say 20 characters then I need to know what they are so I
RD> can flag up a warning.

RD> 2) Count the number of punctuation characters vs. alphanumerics - I
RD> don't want the exclamation mark syndrome shown above, so I need to set
RD> a friendly trade-off limit somehow.

RD> Any thoughts appreciated.

RD> -- 
RD> Best regards,
RD>  Richard Davey
RD>  http://www.phpcommunity.org/wiki/296.html


You could try something like this

$string = "hello world!!!!!!!!!!!!!!!!! how arrrrrrrrrrrrrrre you today?????!!";
if(preg_match_all('/(\w)\1{4,}|(\W)\2{4,}/',$string,$match)){
  echo "too many repeated characters<br>";
  print_r($match);
}
That will catch everything, except numbers, that is repeated 4 or more
times.
-- 
regards,
Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to