ctype函数
PHP ctype_alpha()函数 (PHP ctype_alpha() function)ctype_alpha() function is a character type (CType) function in PHP, it is used to check whether a given string contains only alphabets or not.
ctype_alpha()函数是PHP中的字符类型(CType)函数,用于检查给定的字符串是否仅包含字母。
It returns true – if the string contains only alphabets, else it returns false.
它返回true -如果字符串只包含字母,否则返回FALSE。
Syntax:
句法:
ctype_alpha(string) : boolExample:
例:
Input: "Hello" Output: true Input: "Hello123" Output: false Input: "[email protected]&a" Output: falsePHP code:
PHP代码:
<?php $str = "Hello"; if(ctype_alpha($str)) echo ("$str contains only alphabets.n"); else echo ("$str does not contain only alphabets.n"); $str = "Hello123"; if(ctype_alpha($str)) echo ("$str contains only alphabets.n"); else echo ("$str does not contain only alphabets.n"); $str = "Hello world"; if(ctype_alpha($str)) echo ("$str contains only alphabets.n"); else echo ("$str does not contain only alphabets.n"); $str = "[email protected]&a"; if(ctype_alpha($str)) echo ("$str contains only alphabets.n"); else echo ("$str does not contain only alphabets.n");?>Output
输出量
Hello contains only alphabets.Hello123 does not contain only alphabets.Hello world does not contain only alphabets.[email protected]&a does not contain only alphabets.翻译自: https://www.includehelp.com/php/ctype_alpha-function-with-example.aspx
ctype函数