PHP | ctype_upper()函数

PHP中的ctype_upper()函数用于检查给定字符串的每个字符是否为大写。如果字符串为大写,则返回TRUE,否则返回False。

null

语法:

ctype_upper (string text)

使用的参数:-

  • $text: 测试过的字符串。

返回值: 如果文本的每个字符都是大写,则函数返回True;如果文本不是大写,则函数返回False。

例如:

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.

下面的程序演示了PHP中的ctype_upper()函数:

课程:1

<?php
// PHP program to check given string is
// all characters -Uppercase characters
$string1 = 'GEEKSFORGEEKS' ;
if (ctype_upper( $string1 )) {
// if true then return Yes
echo "Yes" ;
} else {
// if False then return No
echo "No" ;
}
?>


输出:

Yes

课程:2 将字符串数组作为文本传递,并打印单个值的结果。

<?php
// PHP program to check given string is
// all characters -Uppercase characters
$strings = array ( 'GEEKSFORGEEKS' , 'First' ,
'PROGRAMAT2018' , 'ARTICLE' );
// Checking above given four strings
//by used of ctype_upper() function .
foreach ( $strings as $test ) {
if (ctype_upper( $test )) {
// if true then return Yes
echo "Yes" ;
} else {
// if False then return No
echo "No" ;
}
}
?>


输出:

Yes
No
No
Yes

节目:3 驱动代码 ctype_upper() 输入为空格、特殊符号的函数返回False。

<?php
// PHP program to check given string is
// all characters -Uppercase characters
$strings = array ( 'GEEK @ . com' );
// Checking above given four strings
//by used of ctype_upper() function .
foreach ( $strings as $test ) {
if (ctype_upper( $test )) {
// if true then return Yes
echo "Yes" ;
} else {
// if False then return No
echo "No" ;
}
}
?>


输出:

No

参考资料: http://php.net/manual/en/function.ctype-upper.php

© 版权声明
THE END
喜欢就支持一下吧
点赞6 分享