• 首页
  • vue
  • TypeScript
  • JavaScript
  • scss
  • css3
  • html5
  • php
  • MySQL
  • redis
  • jQuery
  • ctype_alpha()

    (PHP 4 >= 4.0.4, PHP 5, PHP 7)

    做纯字符检测

    说明

    ctype_alpha(string $text): bool

    查看提供的string,$text里面的所有字符是否只包含字符。在标准的C语言环境下,字母仅仅是指[A-Za-z]ctype_alpha()等同于(ctype_upper($text)|| ctype_lower($text))如果$text是简单的单个字符串还好,但是在其他语言中有些字母被认为既不是大写也不是小写。

    参数

    $text

    被测试的字符串。

    返回值

    如果在当前语言环境中$text里的每个字符都是一个字母,那么就返回TRUE,反之则返回FALSE

    范例

    一个ctype_alpha()例子(使用默认的语言环境)

    <?php
    $strings = array('KjgWZC', 'arf12');
    foreach ($strings as $testcase) {
        if (ctype_alpha($testcase)) {
            echo "The string $testcase consists of all letters.\n";
        } else {
            echo "The string $testcase does not consist of all letters.\n";
        }
    }
    ?>
    

    以上例程会输出:

    The string KjgWZC consists of all letters.
    The string arf12 does not consist of all letters.
    

    注释

    Note:

    如果给出一个-128 到 255 之间(含)的整数,将会被解释为该值对应的ASCII字符(负值将加上 256 以支持扩展ASCII字符).其它整数将会被解释为该值对应的十进制字符串.

    参见

    It works if you set the locale correctly:
    <?php 
    setLocale(LC_CTYPE, 'FR_fr.UTF-8');
    ?>
    with this change you will get "yes" "yes"

    上篇:ctype_alnum()

    下篇:ctype_cntrl()