PHP中的ctype_alnum()函数检查字母数字字符。如果字符串str中的每个字符都是字母或数字,则返回TRUE,否则返回FALSE。
ctype_alnum(str)
str- 测试的字符串
如果str中的每个字符都是字母或数字,则ctype_alnum()函数将返回TRUE,否则返回FALSE。
以下是一个例子-
<?php $str = array('demo', 'test#$!test'); foreach ($str as $a) { if (ctype_alnum($a)) { echo "$a consists of all letters or digits. \n"; } else { echo "$a does not have all letters or digits. \n"; } } ?>
输出结果
demo consists of all letters or digits. test#$!test does not have all letters or digits.