[英]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.