Introduction

In this article I explain how to check all the character cases in a string using PHP. For checking a character's case in a string I will use two important PHP string functions. This is a very simple technique for checking string cases.

Syntax

This function is basically used for determining if a character is upper case.

ctype_upper($text);

Parameter Description
text To required testing string.

Example

This function returns true when your input character is upper case otherwise it returns false.

<?php

//This syntax value return true

ctype_upper('HELLO')

//This syntax value return false

ctype_upper('hello')

?>

<?php

$str = array('MCNsolution', 'CHARACTER');

foreach ($str as $char)

{

if (ctype_upper($char))

{

echo "$char consists of all uppercase letters.<br>";

} else

{

echo "$char does not have all uppercase letters.<br>";

}

}

?>

Output

cal1.jpg

Syntax

This function is basically used for checking for a lower case character.

ctype_lower($text);

Parameter Description
text To required testing string.

Example

This function returns true when your input character is lower case otherwise it returns false.

<?php

//This syntax value return true

ctype_lower('hello')

//This syntax value return false

ctype_lower('HELLO')

?>

<?php

$str = array('MCNsolution', 'php', '123abc');

foreach ($str as $char)
{

if (ctype_lower($char))
{

echo "The string $char consists of all lowercase letters.<br>";

} else
{

echo "The string $char does not consist of all lowercase letters.<br>";

}

}

?>

Output

cal.jpg