PHP | ctype_alnum()(检查字母数字)

PHP中的一个ctype_alnum()函数,用于检查给定字符串/文本的所有字符是否为字母数字。如果所有字符都是字母数字,则返回TRUE,否则返回FALSE。

null

语法:

 bool ctype_alnum ($text)

使用的参数:

  • $text: 它是指定字符串的必需参数。

例如:

Input  : Geeks
Output : Yes
Explanation : String "Geeks" is alphanumeric.
              Note: Read Standard c local letter.
      
Input  : '%%Contribute_article on GFG!!!'
Output : No
         
Explanation : String contains Special characters.
                 
Note: Except string or digit, if we input anything then it will return FALSE.

下面的程序演示了ctype_alnum()函数。

课程:1 驱动代码 ctype_alnum()() 更好地理解功能。

<?php
// PHP program to check given string is
// all characters are alphanumeric
$string = 'GeeksforGeeks' ;
if ( ctype_alnum( $string ))
echo "Yes" ;
else
echo "No" ;
?>


输出:

Yes

课程:2 驱动一个ctype_alnum()函数的代码,其中的输入将是一个字符串整数数组,字符串带有特殊符号。

<?php
// PHP program to check given string is
// all characters are alphanumeric
$strings = array (
'Geeks' ,
'geek@gmail.com' ,
'2018' ,
'GFG2018' ,
'a b c ' ,
'@!$%^&*()|2018'
);
// Checking above given four strings
// by used of  ctype_alnum() function .
foreach ( $strings as $test ) {
if (ctype_alnum( $test ))
echo "Yes" ;
else
echo "No" ;
}
?>


输出:

Yes
No
Yes
Yes
No
No

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

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