简体   繁体   English

判断PHP中单个字符是否为字母数字的最有效方法是什么?

[英]What's the most efficient way to tell if a single character is alphanumeric in PHP?

What's the most efficient way to tell if a single character is alphanumeric in PHP? 判断PHP中单个字符是否为字母数字的最有效方法是什么?

I know I could do something like: 我知道我可以做类似的事情:

function isSingleAlphaNum($chr){
    if(!is_string($chr){
        return false;
    }

    //capture the first alphanumeric character, replace the whole string with it
    $test = preg_replace('#([a-zA-Z0-9]{1}).*#','$1',$chr);
    if($test == $chr){
        return true;
    }

    return false;

}

This seems clunky. 这看起来笨拙。 Is there a better way? 有没有更好的办法?

好的'ol ctype_alnum() http://www.php.net/manual/zh/function.ctype-alnum.php

ctype_alnum($chr); 

那么ctype-alnum呢?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在PHP中运行异步函数的最有效方法是什么? - What's the most efficient way to run asynchronous functions in PHP? 与Singleton交互的最有效方法是什么? - What's the most efficient way to interact with a Singleton? 在PHP中验证变量的最有效方法是什么? - What is the most efficient way to verify Variables in PHP? 在php中修改字符串的最有效方法是什么? - What is the most efficient way to modify a string in php? 在PHP中附加数组的最有效方法是什么 - What is the most efficient way to append an array in PHP 计算PHP字符串中某个特定字符的所有出现次数的最有效方法是什么? - What is the most efficient way to count all the occurrences of a specific character in a PHP string? 检查每一行到特定字符的最有效方法是什么 - What is the most efficient way to check each line up to a certain character PHP:将大型数组汇总为10个数组的最有效方法是什么? - PHP: What's the most efficient way to summarize a large array into just 10 arrays? 使用分页(PHP,MySQL)时,计算运行总计/余额的最有效方法是什么? - What's the most efficient way to calculate a running total/balance when using pagination (PHP, MySQL) PHP / MySQL / PDO库 - 从数据库中分发信息? 什么是最有效的方式? - PHP/MySQL/PDO Library - Distributing Information Out Of A Database? What's the most efficient way?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM