PHP ctype_upper() Function (With Examples)

In this tutorial, we will learn about the PHP ctype_upper() function with its usage, syntax, parameters, return value, and examples. By IncludeHelp Last updated : December 31, 2023

PHP ctype_upper() function

The ctype_upper() function is a character type (CType) function in PHP, it is used to check whether a given string contains all uppercase characters or not.

Syntax

The syntax of the ctype_upper() function:

ctype_upper(string) : bool

Parameters

The parameters of the ctype_upper() function:

  • string: An input string.

Return Value

The return type of this method is bool, it returns true, if all characters of the given strings are in uppercase, else it returns false.

Sample Input/Output

Input: "HELLO"
Output: true

Input: "HELLO WORLD"
Output: false

Input: "Hello"
Output: false

PHP ctype_upper() Function Example

<?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

The output of the above example is:

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.

To understand the above example, you should have the basic knowledge of the following PHP topics:

All PHP Programs

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.