Write a php function that checks whether a string is all lowercase

Last update on August 19 2022 21:50:30 (UTC/GMT +8 hours)

PHP function: Exercise-5 with Solution

Write a PHP function that checks whether a string is all lower case.

Pictorial Presentation:

Write a php function that checks whether a string is all lowercase

Sample Solution:

PHP Code:

= ord('A') &&
          ord($str1[$sc]) <= ord('Z')) {
      return false;
         }
         }
      return true;
       }
var_dump(is_str_lowercase('abc def ghi'));
var_dump(is_str_lowercase('abc dEf ghi'));
?>

Sample Output:

bool(true)                                                  
bool(false)

Flowchart :

Write a php function that checks whether a string is all lowercase

PHP Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a function to sort an array.
Next: Write a PHP function that checks whether a passed string is a palindrome or not?

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

PHP: Tips of the Day

PHP: How to push both value and key into PHP array?

No, there is no array_push() equivalent for associative arrays because there is no way determine the next key.

You'll have to use

$arrayname[indexname] = $value;

Ref : https://bit.ly/3cp9Gij


  • Exercises: Weekly Top 16 Most Popular Topics
  • SQL Exercises, Practice, Solution - JOINS
  • SQL Exercises, Practice, Solution - SUBQUERIES
  • JavaScript basic - Exercises, Practice, Solution
  • Java Array: Exercises, Practice, Solution
  • C Programming Exercises, Practice, Solution : Conditional Statement
  • HR Database - SORT FILTER: Exercises, Practice, Solution
  • C Programming Exercises, Practice, Solution : String
  • Python Data Types: Dictionary - Exercises, Practice, Solution
  • Python Programming Puzzles - Exercises, Practice, Solution
  • C++ Array: Exercises, Practice, Solution
  • JavaScript conditional statements and loops - Exercises, Practice, Solution
  • C# Sharp Basic Algorithm: Exercises, Practice, Solution
  • Python Lambda - Exercises, Practice, Solution
  • Python Pandas DataFrame: Exercises, Practice, Solution
  • Conversion Tools
  • JavaScript: HTML Form Validation


View Discussion

Improve Article

Save Article

  • Read
  • Discuss
  • View Discussion

    Improve Article

    Save Article

    Given a string, check if all characters of it are in lowercase.
    Examples: 
     

    Input  : gfg123
    Output : No
    Explanation : There are characters
    '1', '2' and '3' that are not lower-
    case
    
    Input  : geeksforgeeks
    Output : Yes
    Explanation : The string "geeksforgeeks" 
    consists of all lowercase letters.

    The above problem can be solved using the in-built functions in PHP. We store multiple values in an array and check using the in-built function in php to check whether all the characters are lowercase.
     

    We solve the given problem using the in-built functions in PHP and iterate from a given array of strings.We use the following in-built function in PHP: 

    • ctype_lower : Returns true if all of the characters in the provided string, text, are lowercase letters. Otherwise returns false.

    PHP

    $strings = array('gfg123', 'geeksforgeeks', 'GfG');

    foreach ($strings as $testcase) {

        if (ctype_lower($testcase)) {

            echo "Yes\n";

        } else {

            echo "No\n";

        }

    }

    ?>

    Output : 

    No
    Yes
    No

    How do you check if a string is in lowercase in PHP?

    ctype_lower() function in PHP The ctype_lower() function check for lowercase character(s). It returns TRUE if every character in text is a lowercase letter in the current locale.

    Which function converts a string to lowercase in PHP?

    The strtolower() function converts a string to lowercase. Note: This function is binary-safe. Related functions: strtoupper() - converts a string to uppercase.

    How do you check if a string contains another string in PHP?

    Answer: Use the PHP strpos() Function You can use the PHP strpos() function to check whether a string contains a specific word or not. The strpos() function returns the position of the first occurrence of a substring in a string. If the substring is not found it returns false .