ctype_alpha
(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)
ctype_alpha — 做純字元檢測
說明
ctype_alpha(string
$text): bool 檢視提供的string,text裡面的所有字元是否只包含字元。
在標準的 C 語言環境下,字母僅僅是指 [A-Za-z] , ctype_alpha() 等同於 (ctype_upper($text) || ctype_lower($text)) 如果 text 是簡單的單個字串還好,但是在其他語言中有些字母被認為既不是大寫也不是小寫。
參數
-
text 被測試的字串。
返回值
如果在目前語言環境中 text 里的每個字元都是一個字母,那麼就返回true,反之則返回false。
範例
示例 #1 一個 ctype_alpha() 例子(使用預設的語言環境)
<?php
$strings = array('KjgWZC', 'arf12');
foreach ($strings as $testcase) {
if (ctype_alpha($testcase)) {
echo "The string $testcase consists of all letters.\n";
} else {
echo "The string $testcase does not consist of all letters.\n";
}
}
?> 以上例程會輸出:
The string KjgWZC consists of all letters. The string arf12 does not consist of all letters.
註釋
注意:
如果給出一個 -128 到 255 之間(含)的int, 將會被解釋為該值對應的ASCII字元 (負值將加上 256 以支援擴充套件ASCII字元). 其它整數將會被解釋為該值對應的十進制字串.
參見
- ctype_upper() - 做大寫字母檢測
- ctype_lower() - 做小寫字元檢測
- setlocale() - 設定地區資訊