PHP 检测是否全为数字或者字母方法ctype_alnum(String text)

来源:互联网 发布:golang ide 编辑:程序博客网 时间:2024/06/05 10:19
<?php
$strings 
= array('AbCd1zyZ9''foo!#$bar');
foreach (
$strings as $testcase) {
    if (
ctype_alnum($testcase)) {
        echo 
"The string $testcase consists of all letters or digits.\n";
    } else {
        echo 
"The string $testcase does not consist of all letters or digits.\n";
    }
}

?>

对于AbCd1zyZ9字符串,由于全是数字或者字符,所以满足条件

The string AbCd1zyZ9 consists of all letters or digits.
对于foo!#$bar字符串,不满足条件。The string foo!#$bar does not consist of all letters or digits.

0 0
原创粉丝点击