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?