(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)
ctype_alpha — 检查字母字符
检查提供的字符串 text
中的所有字符是否都是字母字符。在标准的C
语言环境中,字母只是[A-Za-z]
,并且ctype_alpha() 等效于 (ctype_upper($text) || ctype_lower($text))
(如果 $text 只包含单个字符),但其他语言可能有既不属于大写也不属于小写的字母。
text
被测试的字符串。
注意:
如果提供一个介于 -128 和 255(含)之间的整数,则将其解释为单个字符的 ASCII 值(负值会加上 256 以允许扩展 ASCII 范围内的字符)。任何其他整数都将被解释为包含整数十进制数字的字符串。
示例 #1 一个 ctype_alpha() 示例(使用默认语言环境)
<?php
$strings = array('KjgWZC', 'arf12');
foreach ($strings as $testcase) {
if (ctype_alpha($testcase)) {
echo "字符串 $testcase 全部由字母组成。\n";
} else {
echo "字符串 $testcase 不全部由字母组成。\n";
}
}
?>
以上示例将输出
The string KjgWZC consists of all letters. The string arf12 does not consist of all letters.