(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)
ctype_alpha — 檢查是否為字母字元
檢查提供的 字串 text
中的所有字元是否都是字母。在標準 C
語系中,字母僅為 [A-Za-z]
,如果 $text
只是一個單一字元,則 ctype_alpha() 等同於 (ctype_upper($text) || ctype_lower($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.