字符串中的PHP大写字母

Gur*_*ttu 2 php uppercase

就像标题所说的那样,我正在寻找一种检查字符串中是否包含大写字母的方法。它用于密码字段,我不能使用正则表达式,因为我们在课堂上还没有学过。

我尝试使用ctype_upper,但这仅在字符串中的每个字符均为大写时才起作用。

有没有办法检查字符串中的任何字符,但不使用正则表达式?

Ced*_*ric 5

您可以尝试以下方法:

if (strtolower($string) != $string) {
    echo 'You have uppercase in your string';
} else {
    echo 'You have no uppercase in your string';
}
Run Code Online (Sandbox Code Playgroud)

这将检查转换为小写的字符串是否等于原始字符串。希望这可以帮助...