ctype函数_PHP ctype_alpha()函数与示例

清疚 2023-03-05 15:49 66阅读 0赞

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:

句法:

  1. ctype_alpha(string) : bool

Example:

例:

  1. Input: "Hello"
  2. Output: true
  3. Input: "Hello123"
  4. Output: false
  5. Input: "[email protected]&a"
  6. Output: false

PHP code:

PHP代码:

  1. <?php
  2. $str = "Hello";
  3. if(ctype_alpha($str))
  4. echo ("$str contains only alphabets.\n");
  5. else
  6. echo ("$str does not contain only alphabets.\n");
  7. $str = "Hello123";
  8. if(ctype_alpha($str))
  9. echo ("$str contains only alphabets.\n");
  10. else
  11. echo ("$str does not contain only alphabets.\n");
  12. $str = "Hello world";
  13. if(ctype_alpha($str))
  14. echo ("$str contains only alphabets.\n");
  15. else
  16. echo ("$str does not contain only alphabets.\n");
  17. $str = "[email protected]&a";
  18. if(ctype_alpha($str))
  19. echo ("$str contains only alphabets.\n");
  20. else
  21. echo ("$str does not contain only alphabets.\n");
  22. ?>

Output

输出量

  1. Hello contains only alphabets.
  2. Hello123 does not contain only alphabets.
  3. Hello world does not contain only alphabets.
  4. [email protected]&a does not contain only alphabets.

翻译自: https://www.includehelp.com/php/ctype_alpha-function-with-example.aspx

ctype函数

发表评论

表情:
评论列表 (有 0 条评论,66人围观)

还没有评论,来说两句吧...

相关阅读