字串中的底線將導致結果為 false,因此您必須先移除它們。
(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)
ctype_upper — 檢查大寫字元
text
要測試的字串。
注意事項:
如果提供 -128 到 255 之間(含)的 整數,它會被解釋為單個字元的 ASCII 值(負值會加上 256,以便允許擴展 ASCII 範圍內的字元)。任何其他整數都會被解釋為包含整數十進位數字的字串。
範例 #1 ctype_upper() 範例(使用預設語系環境)
<?php
$strings = array('AKLWC139', 'LMNSDO', 'akwSKWsm');
foreach ($strings as $testcase) {
if (ctype_upper($testcase)) {
echo "字串 $testcase 全由大寫字母組成。\n";
} else {
echo "字串 $testcase 並非全由大寫字母組成。\n";
}
}
?>
以上範例將輸出:
The string AKLWC139 does not consist of all uppercase letters. The string LMNSDO consists of all uppercase letters. The string akwSKWsm does not consist of all uppercase letters.