ctype_upper():Checking for all upper case chars

$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()
We can check a string to know if all characters present are in upper case letters or not.

Return value will be TRUE ( if all are Upper case chars ) or FALSE.

Here is the code 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

Presence of Blank space

This function checks for lower cases chars only so presence of any blank space will return as FALSE 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

Presence of Special characters

Presence of Special characters will also return FALSE , only change the string part like this in above code.
$string='ABC)DEF';
Output will be
All or some characters are NOT Upper case

Examples multiple strings & ctype_upper()

$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
ctype()
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    Post your comments , suggestion , error , requirements etc here





    PHP video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer