ctype_cntrl()是PHP中的一个内置函数,用于检查字符串/文本中的所有字符是否为控制字符。控制字符包括换行符、制表符、转义符等。 语法:
null
bool ctype_cntrl ( $str )
参数: 此函数接受单个参数$str。它是指定字符串的必需参数。 返回值: 如果字符串仅包含控制字符,则返回True;如果失败,则返回False。 例如:
Input: GeeksforGeeksOutput: NoExplanation: String (GeeksforGeeks) contains only the alphanumeric characters.Input: Output: YesExplanation: String ( ) contains only the control character.
下面的程序演示了ctype_cntrl()函数。 项目1:
php
<?php // PHP program to check if a string has all // control characters $str1 = "GeeksforGeeks" ; if ( ctype_cntrl( $str1 )) echo "Yes" ; else echo "No" ; $str2 = " " ; if ( ctype_cntrl( $str2 )) echo "Yes" ; else echo "No" ; ?> |
输出:
NoYes
项目2: ctype_cntrl()函数的实现,该函数接收包含整数和特殊符号的字符串数组的输入。
php
<?php // PHP program to check if a string has all // control characters $str = array ( "Geeks" , "Geeks space" , "@@##-- /" , "" , " , " ); // Check the above strings by using // ctype_cntrl() function foreach ( $str as $test ) { if (ctype_cntrl( $test )) echo "Yes" ; else echo "No" ; } ?> |
输出:
NoNoNoYesNoYes
参考资料: http://php.net/manual/en/function.ctype-cntrl.php
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END