PHP | ctype_punct()函数

PHP中的ctype_punct()函数用于检查给定字符串的所有字符是否都是标点字符。如果所有字符都是标点符号,则此函数返回TRUE,否则返回FALSE。

null

笔记 :标点符号有:句点、逗号、问号、连字符、破折号、括号、撇号、省略号、引号、冒号、分号、感叹号。

语法:

ctype_punct( $text )

参数: 此函数只接受一个参数 文本 。这是一个指定输入字符串的强制参数。

返回值: 如果$text中的每个字符都是标点符号,则函数返回TRUE,否则返回False。

例子 :

Input  : @#$$.&*()_+;><?~
Output : Yes

Input  : GeeksforGeeks@2018
Output : No

Note: The string should not contain a letter, blank-space  or digit.  

下面的程序演示了ctype_punct()函数: 课程:1

<?php
// PHP program to check given string is
// punctuation character or not
$string = 'GeeksforGeeks' ;
if ( ctype_punct( $string ))
echo "Yes " ;
else
echo "No " ;
?>


输出:

No

课程:2

<?php
// PHP program to check given string is
// punctuation character or not
$strings = array (
"Reg no CE:20" ,
'()()()()' ,
'GFG' ,
'@@@@##$$%^^' ,
''
);
// Checking above given strings
//by used of ctype_punct() function .
foreach ( $strings as $test ) {
if (ctype_punct( $test ))
echo "Yes " ;
else
echo "No " ;
}
?>


输出:

No 
Yes 
No 
Yes 
No

参考 : http://php.net/manual/en/function.ctype-punct.php

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