ctype_upper():Checking for all upper case by using ctype_upper()

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.


Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com




    PHP String Functions

    Post your comments , suggestion , error , requirements etc here .




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