English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The ctype_alnum() function checks if the string is composed entirely of letters and/or numbers characters.
ctype_alnum(\$text);
It checks whether all characters in the provided string are letters and/or numbers.
In the standard C language environment, letters are only [A-Za-z], this function is equivalent to preg_match('/^[a-z0-9]+$/iD ', $text).
Serial Number | Parameters and Description |
---|---|
1 | text(Required) The string to be checked |
If each character in the text is a letter or number, it returns TRUE, otherwise it returns FALSE.
Traverse the array elements to check if they are all alphanumeric
<?php \$strings = array('hello', 'foo!#$bar'); foreach (\$strings as \$example) { if (ctype_alnum(\$example)) { echo "\$example is composed of letters or numbers.\n"; }else { echo "\$example is not entirely letters or numbers.\n"; } } ?>Test and see‹/›
Output Result:
hello is composed of letters or numbers. foo!#$bar is not entirely letters or numbers.