函数名: ctype_upper()
函数描述:检查字符串中的所有字符是否都是大写字母
用法:
bool ctype_upper ( string $text )
参数:
- $text:要检查的字符串。
返回值:
- 如果字符串中的所有字符都是大写字母,则返回 true。
- 如果字符串包含任何非大写字母的字符,则返回 false。
示例:
$text = "HELLO";
var_dump(ctype_upper($text)); // 输出: bool(true)
$text = "Hello";
var_dump(ctype_upper($text)); // 输出: bool(false)
$text = "123";
var_dump(ctype_upper($text)); // 输出: bool(false)
$text = "";
var_dump(ctype_upper($text)); // 输出: bool(true)
说明:
- ctype_upper() 函数用于检查字符串中的字符是否全为大写字母。如果字符串为空,则也被认为是全为大写字母,返回 true。
- 该函数对于非ASCII字符可能会返回不准确的结果,因为它仅适用于ASCII字符集。
- 如果需要检查一个字符串是否只包含字母字符,可以使用 ctype_alpha() 函数。
- ctype_upper() 是一个函数,无需引入特定的扩展即可使用,它是PHP内置的函数。