首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

ctype_alnum

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

ctype_alnum - 检查字母数字字符(s)

描述

代码语言:javascript
复制
bool ctype_alnum ( string $text )

检查提供的字符串中的所有字符text是否都是字母数字。

参数

text

被测试的字符串。

返回值

如果文本中的每个字符都是字母或数字,则返回TRUE,否则返回FALSE。

例子

示例#1 ctype_alnum()示例(使用默认语言环境)

代码语言:javascript
复制
<?php
$strings = array('AbCd1zyZ9', 'foo!#$bar');
foreach ($strings as $testcase) {
    if (ctype_alnum($testcase)) {
        echo "The string $testcase consists of all letters or digits.\n";
    } else {
        echo "The string $testcase does not consist of all letters or digits.\n";
    }
}
?>

上面的例子将输出:

代码语言:javascript
复制
The string AbCd1zyZ9 consists of all letters or digits.
The string foo!#$bar does not consist of all letters or digits.

注意

注意:如果提供了-128到255之间的整数,则它将被解释为单个字符的ASCII值(为了允许扩展ASCII范围中的字符,负值将被添加256)。任何其他整数都被解释为包含整数的十进制数字的字符串。

扩展内容

  • ctype_alpha() - 检查字母字符(s)
  • ctype_digit() - 检查数字字符(s)
  • setlocale() - 设置区域设置信息

ctype_alpha →

扫码关注腾讯云开发者

领取腾讯云代金券