2011-08-26 36 views
2

什麼是最有效的方式來判斷單個字符是否在PHP中是字母數字?什麼是最有效的方式來判斷一個字符是否在PHP中是字母數字?

我知道我可以做這樣的事情:

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; 

} 

這似乎笨重。有沒有更好的辦法?

回答

相關問題