PHP中的ctype_upper()函数检查大写字符。如果文本中的每个字符在当前语言环境中均为大写字母,则返回TRUE。
ctype_upper(str)
str-测试的字符串
如果文本中的每个字符在当前语言环境中均为大写字母,则ctype_upper()函数将返回TRUE。
以下是一个例子-
<?php $arr = array('9898jjhh', 'PQR', 'Amit'); foreach ($arr as $demo) { if (ctype_upper($demo)) { echo "$demo has all uppercase letters. \n"; } else { echo "$demo does not have all uppercase letters. \n"; } } ?>
输出结果
以下是输出-
9898jjhh does not have all uppercase letters. PQR has all uppercase letters. Amit does not have all uppercase letters.
让我们看另一个例子-
<?php $str = 'AUSTRALIA'; if (ctype_upper($str)) { echo "Word has all uppercase characters!\n"; } else { //如果为False,则返回No- echo "Word does not have all uppercase characters!\n"; } ?>
输出结果
以下是输出-
Word has all uppercase characters!