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

本文详细介绍了PHP中的ctype_alpha()函数,该函数用于检查给定的字符串是否仅由字母组成。通过实例演示了如何使用此函数进行字符串验证。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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) : bool

Example:

例:

    Input: "Hello"
    Output: true
    Input: "Hello123"
    Output: false
    Input: "[email protected]&a"
    Output: false

PHP 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函数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值