Home > Article > Backend Development > PHP function to determine uppercase and lowercase letters_PHP tutorial
Provide a simple example of the PHP function for judging uppercase and lowercase letters. It can find out how many uppercase letters and lowercase letters there are in a string. It is a very convenient and commonly used function.
Provide a simple example of the PHP tutorial to determine the uppercase and lowercase letters function. It can find out how many uppercase letters and how many lowercase letters a string has. It is a very convenient and commonly used function.
function checkcase($str){
If(preg_match('/^[a-z]+$/', $str)){
echo 'lowercase letters';
}elseif(preg_match('/^[a-z]+$/', $str)){
echo 'uppercase letters';
}
}
Method 2
$str = 'a';
function checkcase1($str){
$str = ord($str);
If($str>64&&$str<91){
echo 'uppercase letters';
return;
}
If($str>96&&$str<123){
echo 'lowercase letters';
return;
}
echo 'Not a letter';
}
function checkcase2($str){
If(strtoupper($str)===$str){
echo 'uppercase letters';
}else{
echo 'lowercase letters';
}
}
echo checkcase1($str);
echo checkcase2($str);
?>