Re: [PHP] count characters without space

2003-01-11 Thread Jeffrey B. Ferland
> who knowes how to count the charcaters in a string without the space
> character?

Using a regular expression to strip out all the spaces before passing to the
word counting function seems easiest. You'll be left to adapt it to PHP, but
the regexp is: 's/ //g' That removes all spaces. If it gives an error, try
s/\ //g to escape the space. Pass the result to whatever you use to count
the number of characters.

-Jeff
SIG: HUP


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




Re: [PHP] count characters without space

2003-01-11 Thread Gerald Timothy Quimpo
On Saturday 11 January 2003 08:51 pm, [EMAIL PROTECTED] wrote:
> who knowes how to count the charcaters in a string without the space
> character?

you need to be more clear.

number of characters in the string except space?
number of distinct characters in the string except space?
include other non-space whitespace (\t \n \r etc)?

case sensitive?

this is really not hard at all and would be educational for you to 
write yourself, as an exercise in learning php.

one approach:

1.  create an empty string, charsfound.  
 for each character in your input string, see if the character already 
exists in charsfound (use strchr or strpos).  
if it's a space, continue the loop (don't exec the code below).
if  it's already there, skip to the next character.
if it's not yet there, increment a counter, add the character to
charsfound and continue the loop.

 at the end of the input string exit the loop.  the counter is the
 number of distinct non-space characters in the input string.

 putting the "increment a counter" elsewhere (but in the appropriate
 places) in the  loop will give you the number of non-space (not distinct)
 characters in the input string.

tiger

-- 
Gerald Timothy Quimpo  tiger*quimpo*org gquimpo*sni-inc.com tiger*sni*ph
Public Key: "gpg --keyserver pgp.mit.edu --recv-keys 672F4C78"
   Veritas liberabit vos.
   Doveryai no proveryai.

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




[PHP] count characters without space

2003-01-11 Thread harald.mohring
who knowes how to count the charcaters in a string without the space
character?

thanks harry



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