What's the most efficient way to tell if a single character is alphanumeric in 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
呢?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.