ctype_lower(): Checking for all lower case letters

Check whether all characters are lowercase or uppercase

Use ctype_lower() or ctype_upper() with string input when every character must satisfy the selected case test. An empty string returns false, and non-string arguments should not be used as character-code shortcuts in current PHP.

$lower = 'php';
$upper = 'PHP';
var_dump(ctype_lower($lower)); // true
var_dump(ctype_upper($upper)); // true

The examples below show additional variations, expected output and practical usage.

$string='abcasdf';
if (ctype_lower($string)) {
echo " All characters are Lower case only ";
}else{
echo " All characters are not lower case  ";
}
The output of above code will be
All characters are Lower case only
Syntax
ctype_lower($input_string);
ctype_upper($input_string);

Each function returns true only when every character in the non-empty string satisfies the requested case test; otherwise it returns false.

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 asdf';

if (ctype_lower($string)) {
echo " All characters are Lower case only ";
}else{
echo " Not all characters are lower case  ";
}
Output will be
Not all characters are lower 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)asdf';
Output will be
Not all characters are lower case

Examples multiple strings & ctype_lower()

$str = array("hello world", "abcdef", "ab#cd", "34", "442");
foreach ($str as $val){
if (ctype_lower($val)){
 echo "<p class='text-success'>The string <b>$val</b> consists of lower Case letters .</p>";
 } else {
 echo "<p class='text-danger'>The string <b>$val</b> does not consist of all lower case letters.</p>";
}
}
The string hello world does not consist of all lowercase letters.
The string abcdef consists of lowercase letters.
The string ab#cd does not consist of all lowercase letters.
The string 34 does not consist of all lowercase letters.
The string 442 does not consist of all lowercase letters.

String Functions Check for Upper case chars only ucwords(): To Change first char of all words to upper case of a string. how to change all the letters to upper case Converting string to all lower case letters


Subscribe to our YouTube Channel here



plus2net.com











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