Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php
character
lowercase
communitycreator

What is the ctype_lower method in PHP?

Programming Bytes

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The ctype_lower method checks if all the text characters are in lowercase alphabetical characters.

The lowercase alphabetical characters include a-z.

Syntax

ctype_lower(mixed $text): bool

This method returns a Boolean value.

Code

<?php
$str = "abc";
printIsLower($str);
$str = "aaaaa";
printIsLower($str);
$str = "A";
printIsLower($str);
$str = "123abc";
printIsLower($str);
function printIsLower($str){
echo "The string is: ". $str. "\n";
echo "Is Lower: ";
var_dump(ctype_lower($str));
echo "---------\n";
}
?>

Explanation

In the code above:

  • We used the ctype_lower method to check if the string contains only lowercase alphabetical characters.

  • For the string abc and aaaa, the ctype_lower method returns true.

  • But for the string A and 123abc, the ctype_lower method returns false because the string contains the uppercase letter A and numeric characters, respectively.


Things to note

If an int value ranging from -128 to 128 is passed as an argument, it is internally converted as an ASCII character. Then it is checked if the converted character is a numeric character. See the example below.

<?php
var_dump(ctype_lower(97)); // 97 is equivalent to charcter `a` in ASCII
?>

In the code above, we passed 97 as an argument. First, it is internally converted as ASCII character a and then checked if it is a lowercase alphabetical character. a is a lowercase character, so true is returned.

RELATED TAGS

php
character
lowercase
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring