Computer >> Computer tutorials >  >> Programming >> PHP

ctype_upper() function in PHP


The ctype_upper() function in PHP check for uppercase character(s). It returns TRUE if every character in text is an uppercase letter in the current locale.

Syntax

ctype_upper(str)

Parameters

  • str − The tested string

Return

The ctype_upper() function returns TRUE if every character in text is an uppercase letter in the current locale.

Example

The following is an example −

<?php
   $arr = array('9898jjhh', 'PQR', 'Amit');

   foreach ($arr as $demo) {
      if (ctype_upper($demo)) {
         echo "$demo has all uppercase letters. \n";
      } else {
         echo "$demo does not have all uppercase letters. \n";
      }
   }
?>

Output

The following is the output −

9898jjhh does not have all uppercase letters.
PQR has all uppercase letters.
Amit does not have all uppercase letters.

Example

Let us see another example −

<?php
   $str = 'AUSTRALIA';

   if (ctype_upper($str)) {
      echo "Word has all uppercase characters!\n";
   } else {
      // if False then return No
      echo "Word does not have all uppercase characters!\n";
   }
?>

Output

The following is the output −

Word has all uppercase characters!