PHP ctype_upper() function with example

PHP ctype_upper() work: Here, we will find out about the ctype_upper() work with the example in PHP.

PHP ctype_upper() work

ctype_upper() work is a character type (CType) work in PHP, it is utilized to check whether a given string contains every single capitalized character or not.

It returns genuine, if all characters of the given strings are in capitalized, else it returns false.

Syntax:

    ctype_upper(string) : bool

Example:

    Input: "HELLO"
    Output: true
    Input: "HELLO WORLD"
    Output: false
    Input: "Hello"
    Output: false

PHP Code:

<?php
    $str = "HELLO";
    if(ctype_upper($str))
        echo ("$str contains all uppercase characters.\n");
    else
        echo ("$str does not contain all uppercase characters.\n");

    $str = "HELLO WORLD"; //space is there
    if(ctype_upper($str))
        echo ("$str contains all uppercase characters.\n");
    else
        echo ("$str does not contain all uppercase characters.\n");

    $str = "HELLO123"; //digits are there 
    if(ctype_upper($str))
        echo ("$str contains all uppercase characters.\n");
    else
        echo ("$str does not contain all uppercase characters.\n");

    $str = "Hello"; //lowercase characters are there
    if(ctype_upper($str))
        echo ("$str contains all uppercase characters.\n");
    else
        echo ("$str does not contain all uppercase characters.\n");	
?>

Output

HELLO contains all uppercase characters.
HELLO WORLD does not contain all uppercase characters.
HELLO123 does not contain all uppercase characters.
Hello does not contain all uppercase characters.

Leave a Comment

error: Alert: Content is protected!!