Re: Counting number of characters without spaces between them?

From: Date: Fri, 23 Apr 2004 16:41:59 +0000
Subject: Re: Counting number of characters without spaces between them?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-184429@lists.php.net to get a copy of this message
--- Richard Davey <rich@launchcode.co.uk> wrote: > I want to be able to check to see if, in a string, the user has > entered too many consecutive characters and not enough spaces. For > example they might enter a subject like: > > "hello world!!!!!!!!!!!!!!!!! how arrrrrrrrrrrrrrre you today?????!!" > > Does anyone have a nice technique for checking the following: > > 1) Count the length of the words in the string, i.e. if there are any > words beyond say 20 characters then I need to know what they are so I > can flag up a warning. You can explode on a space and loop through the resulting array, checking strlen() as you go. > 2) Count the number of punctuation characters vs. alphanumerics - I > don't want the exclamation mark syndrome shown above, so I need to set > a friendly trade-off limit somehow. Perhaps substr_count() and a bit of guesswork to find an acceptable proportion of punctuation allowed? Chris ===== Chris Shiflett - http://shiflett.org/ PHP Security - O'Reilly Coming Fall 2004 HTTP Developer's Handbook - Sams http://httphandbook.org/ PHP Community Site http://phpcommunity.org/

« previous php.general (#184429) next »