PHP | ctype_upper() Function
Last Updated :
04 Jun, 2018
The ctype_upper() function in PHP used to check each and every character of a given string is in uppercase or not. If the string in upper case then it returns TRUE otherwise returns False.
Syntax:
ctype_upper (string text)
Parameter Used:-
- $text : The tested string.
Return Value:
Function returns True if each character of text in Upper Case or False if text is not in upper case.
Examples:
Input : GEEKSFORGEEKS
Output : Yes
Explanation: All characters of "GEEKSFORGEEKS"
in UPPERCASE.
Input : GFG2018
Output : No
Explanation : In text "GFG2018", '2', '0', '1', '8'
are not in UPPERCASE.
Input : GFG INDIA
Output : No
Explanation : In String "GFG INDIA" a special character [space]
between GFG and INDIA. so answer will be No.
Note: Except string, if we input anything then it will return FALSE.
Below program illustrates the ctype_upper() function in PHP:
Program: 1
<?php
$string1 = 'GEEKSFORGEEKS' ;
if (ctype_upper( $string1 )) {
echo "Yes\n" ;
} else {
echo "No\n" ;
}
?>
|
Program: 2 passing array of string as text and print result for individual values.
<?php
$strings = array ( 'GEEKSFORGEEKS' , 'First' ,
'PROGRAMAT2018' , 'ARTICLE' );
foreach ( $strings as $test ) {
if (ctype_upper( $test )) {
echo "Yes\n" ;
} else {
echo "No\n" ;
}
}
?>
|
Program: 3 Drive a code ctype_upper() function where input will be space, special symbol, returns False.
<?php
$strings = array ( 'GEEK @ . com' );
foreach ( $strings as $test ) {
if (ctype_upper( $test )) {
echo "Yes\n" ;
} else {
echo "No\n" ;
}
}
?>
|
References : http://php.net/manual/en/function.ctype-upper.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...