PHP 检查字符或者字符串 是否仅包含指定类型的字符 ctype 系列函数

发布时间 2023-05-23 15:18:31作者: 小鱼大虾
$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";
    }
}

上面只是一个列子,更多请自行查阅