Home » PHP » PHP Ctype functions

PHP ctype_upper() function with example

PHP ctype_upper() function: Here, we are going to learn about the ctype_upper() function with example in PHP.
Submitted by IncludeHelp, on February 04, 2019

PHP ctype_upper() function

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.

It returns true, if all characters of the given strings are in uppercase, 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.





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.