相關(guān)關(guān)鍵詞
關(guān)于我們
最新文章
PHP中快速生成隨機密碼的幾種方式
思路是這樣的,密碼通常是英文字母和數(shù)字的混合編排,我們可以借助隨機函數(shù)rand函數(shù)隨機的選擇一個長字符串的一部分。
function random_code($length = 8,$chars = null){ if(empty($chars)){ $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; } $count = strlen($chars) - 1; $code = ''; while( strlen($code) < $length){ $code .= substr($chars,rand(0,$count),1); } return $code; } echo random_code;//A1zYbN5X