PHP | ctype_upper() Function

The ctype_upper() function in PHP used to check each and every character of a given string is in uppercase or not. If the string in upper case then it returns TRUE otherwise returns False.

Syntax:

ctype_upper (string text)

Parameter Used:-

  • $text : The tested string.

Return Value:
Function returns True if each character of text in Upper Case or False if text is not in upper case.

Examples:



Input  : GEEKSFORGEEKS
Output : Yes
Explanation: All characters of  "GEEKSFORGEEKS" 
             in UPPERCASE.

Input  : GFG2018
Output : No
Explanation : In text "GFG2018",  '2', '0', '1', '8'
              are not in UPPERCASE.

Input : GFG INDIA
Output : No
Explanation : In String "GFG INDIA" a special character [space] 
              between GFG and INDIA. so answer will be No.
                   
Note: Except string, if we input anything then it will return FALSE.

Below program illustrates the ctype_upper() function in PHP:

Program: 1

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP program to check given string is 
// all characters -Uppercase characters
  
$string1 = 'GEEKSFORGEEKS';
  
   if (ctype_upper($string1)) {
         
        // if true then return Yes
        echo "Yes\n";
    } else {
          
        // if False then return No
        echo "No\n";
    }
?>

chevron_right


Output:

Yes

Program: 2 passing array of string as text and print result for individual values.

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// PHP program to check given string is 
// all characters -Uppercase characters
  
$strings = array('GEEKSFORGEEKS', 'First'
                'PROGRAMAT2018', 'ARTICLE');
  
// Checking above given four strings 
//by used of ctype_upper() function .
  
foreach ($strings as $test) {
      
    if (ctype_upper($test)) {
        // if true then return Yes
        echo "Yes\n";
    } else {
        // if False then return No
        echo "No\n";
    }
}
  
?>

chevron_right


Output:

Yes
No
No
Yes

Program: 3 Drive a code ctype_upper() function where input will be space, special symbol, returns False.

filter_none

edit
close

play_arrow

link
brightness_4
code

     
<?php
// PHP program to check given string is 
// all characters -Uppercase characters
  
$strings = array('GEEK @ . com');
  
// Checking above given four strings 
//by used of ctype_upper() function .
  
foreach ($strings as $test) {
      
    if (ctype_upper($test)) {
        // if true then return Yes
        echo "Yes\n";
    } else {
        // if False then return No
        echo "No\n";
    }
}
  
?>

chevron_right


Output:

No

References : http://php.net/manual/en/function.ctype-upper.php



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.