PHP Check if all characters are lower case Last Updated : 18 Jul, 2024 Summarize Suggest changes Share Like Article Like Report Given a string, check if all characters of it are in lowercase.Examples: Input : gfg123Output : NoExplanation : There are characters'1', '2' and '3' that are not lower-caseInput : geeksforgeeksOutput : YesExplanation : The string "geeksforgeeks" consists of all lowercase letters.Below we are some common methods to check if all characters are lower caseTable of ContentUsing ctype_lower()Using a Regular Expression with preg_match()Using ctype_lower()In this approach we are using ctype_lower in PHP to check if each string in an array contains only lowercase characters. The function returns true if all characters are lowercase, otherwise false. This efficiently validates the case of characters within each string.Example: PHP <?php // PHP program to check if a string has all // lower case characters $strings = array('gfg123', 'geeksforgeeks', 'GfG'); // Checking for above three strings one by one. foreach ($strings as $testcase) { if (ctype_lower($testcase)) { echo "Yes\n"; } else { echo "No\n"; } } ?> OutputNo Yes No Using a Regular Expression with preg_match()The preg_match() function in PHP can be used to check if a string matches a specific pattern. In this case, we can use a regular expression to determine if all characters in the string are lowercase letters.Example: PHP <?php // Function to check if all characters in a string are lowercase function all_lowercase($string) { return preg_match('/^[a-z]+$/', $string) === 1; } // Test array of strings $strings = ["gfg123", "geeksforgeeks", "GeeksForGeeks"]; // Iterate through the array and check each string foreach ($strings as $str) { if (all_lowercase($str)) { echo "Yes\n"; } else { echo "No\n"; } } ?> OutputNo Yes No Advertise with us Next Article How to check if a String contains a Specific Character in PHP ? S Shubham_Singh_29 Follow Similar Reads How to remove non-alphanumeric characters in PHP? Non-alphanumeric characters can be remove by using preg_replace() function. This function perform regular expression search and replace. The function preg_replace() searches for string specified by pattern and replaces pattern with replacement if found. Examples: Input : !@GeeksforGeeks2018? Output 2 min read PHP | ctype_alnum() (Check for Alphanumeric) A ctype_alnum() function in PHP used to check all characters of given string/text are alphanumeric or not. If all characters are alphanumeric then return TRUE, otherwise return FALSE. Syntax: bool ctype_alnum ($text) Parameters Used: $text : It is a mandatory parameter which specifies the string. Ex 2 min read PHP | array_change_key_case() Function The array_change_key_case() function is an inbuilt function in PHP and is used to change case of all of the keys in a given array either to lower case or upper case. Syntax: array array_change_key_case(in_array, convert_case) Parameters: This function accepts two parameters out of which one is manda 3 min read How to check if a String contains a Specific Character in PHP ? In PHP, determining whether a string contains a specific character is a common task. Whether you're validating user input, parsing data, or performing text processing, PHP provides several methods to check for the presence of a particular character within a string efficiently. Here are some common a 2 min read PHP Program to Check Whether a Character is a Vowel or Consonant There are a total of 26 letters in the English alphabet. There are 5 vowel letters and 21 consonant letters. The 5 vowel letters are: "a", "e", "i", "o", and "u" rest are consonants. There are different approaches to checking whether a character is a vowel or a consonant. These are the different App 3 min read PHP | ctype_alpha() (Checks for alphabetic value) A ctype_alpha() function in PHP used to check all characters of a given string are alphabetic or not. If all characters are alphabetic then return True otherwise return False. Syntax: ctype_alpha($text) Parameters Used: $text :- It is a mandatory parameter which specifies the string. Return Value: I 2 min read Article Tags : Misc Web Technologies PHP PHP-string PHP-function +1 More Practice Tags : Misc Like