$var="ABCD"; // All are Upper case character(s)
//$var="abCD"; // All or some are NOT Upper case character(s)
//$var="12AB"; // All or some are NOT Upper case character(s)
//$var="#%AB"; // All or some are NOT Upper case character(s)
if(ctype_upper($var)){
echo "$var All are Upper case character(s)";
}else{
echo " $var All or some are NOT Upper case character(s)";
}
output
ABCD All are Upper case character(s)Syntax
ctype_upper($input_string);
Checking for presence of only upper case letters by using ctype_upper() $string='ABCDEF';
if (ctype_upper($string)) {
echo " All characters are Upper case only ";
}else{
echo " All or some characters are NOT Upper case ";
}
The output of above code will be
All characters are Upper case only
$string='ABC DEF';
if (ctype_lower($string)) {
echo " All characters are Upper case only ";
}else{
echo "All or some characters are NOT Upper case ";
}
Output will be
All or some characters are NOT Upper case
$string='ABC)DEF';
Output will be All or some characters are NOT Upper case
$str = array("HELLO WORLD", "ABCDEF", "AB!CD","67");
foreach ($str as $val){
if (ctype_upper($val)){
echo "<p class='text-success'>The string $val consists of Upper Case letters .</p>";
} else {
echo "<p class='text-danger'>The string $val does not consist of all Upper case letters.</p>";
}
}
Output is here
The string HELLO WORLD does not consist of all Upper case letters.
The string ABCDEF consists of Upper Case letters .
The string AB!CD does not consist of all Upper case letters.
The string 67 does not consist of all Upper case letters.
Check for only alphabetic characters by ctype_alpha()
Check for all lower or upper
Check for at least one lower case or upper case
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.