Web Hosting Talk







View Full Version : php function: ischar()


hostgrid
06-27-2003, 03:11 PM
is there a php function anyone knows of that will tell me if a character is a letter?

for example if the character is '0' or 'd' or 'b' it would return TRUE but if the character was ';' or '{' then it would return FALSE

thanks,
Matt

plugged
06-27-2003, 03:23 PM
function is_char($chr) {
return ereg([a-zA-Z],$chr);
}

Lagniappe-labgeek
06-27-2003, 03:47 PM
ctype_alpha(sting) - true for [a-z or A-Z] checks whole string.

May also want to see the others:
ctype_alnum -- Check for alphanumeric character(s)
ctype_alpha -- Check for alphabetic character(s)
ctype_cntrl -- Check for control character(s)
ctype_digit -- Check for numeric character(s)
ctype_graph -- Check for any printable character(s) except space
ctype_lower -- Check for lowercase character(s)
ctype_print -- Check for printable character(s)
ctype_punct -- Check for any printable character which is not whitespace or an alphanumeric character
ctype_space -- Check for whitespace character(s)
ctype_upper -- Check for uppercase character(s)
ctype_xdigit -- Check for character(s) representing a hexadecimal digit

http://www.php.net/manual/en/ref.ctype.php

From that page --
Editors note:

CTYPE functions are always prefered, when possible, to Regular Expressions and, often, even to some equivalent str_*, is_* functions. This is because of the fact that CTYPE uses a native C library and thus processes signitificaly faster.

Maxim Maletsky
maxim at php dot net

hostgrid
06-27-2003, 03:50 PM
Thanks fellas, I got it!